using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace CURDFiddler.Models
{
public class UsersRepository
{
public static List<UserInfo> GetAllUsers()
{
MuditaEntities1 dataContext=new MuditaEntities1();
var query = from user in dataContext.UserInfoes
select user;
return query.ToList();
}
public static UserInfo GetUser(string userID)
{
MuditaEntities1 dataContext=new MuditaEntities1();
var query = (from user in dataContext.UserInfoes
where user.UId==userID
select user).SingleOrDefault();
return query;
}
public static void InsertUser(UserInfo newUser)
{
MuditaEntities1 dataContext = new MuditaEntities1();
dataContext.UserInfoes.Add(newUser);
dataContext.SaveChanges();
}
public static void UpdateUser(UserInfo oldUser)
{
MuditaEntities1 dataContext = new MuditaEntities1();
var query = (from user in dataContext.UserInfoes
where user.UId==oldUser.UId
select user).SingleOrDefault();
query.UId= oldUser.UId;
query.UserName = oldUser.UserName;
query.Address = oldUser.Address;
dataContext.SaveChanges();
}
public static void DeleteUser(string UId)
{
MuditaEntities1 dataContext = new MuditaEntities1();
var query = (from user in dataContext.UserInfoes
where user.UId == UId
select user).SingleOrDefault();
dataContext.UserInfoes.Remove(query);
dataContext.SaveChanges();
}
}
}