/// <summary> /// Método para crear nuevos usuarios. /// </summary> /// <param name="newUser"></param> /// <returns></returns> public static UserDTO CreateUser(UserDTO newUser) { using (DutiesFamilyEntities dataContext = new DutiesFamilyEntities()) { if (dataContext.User.Count(x => x.Email.Trim() == newUser.Email.Trim()) == 0) { var user = new User(); user.Email = newUser.Email; user.Family = dataContext.Family.FirstOrDefault(x => x.IdFamily == newUser.IdFamily); user.IdFamily = newUser.IdFamily; user.Rol = dataContext.Rol.FirstOrDefault(x => x.IdRol == newUser.IdRol); user.IdRol = newUser.IdRol; user.Image = newUser.Image; user.Password = Guid.NewGuid().ToString().Split('-').FirstOrDefault(); user.UserName = newUser.UserName; dataContext.User.Add(user); dataContext.SaveChanges(); newUser.Password = user.Password; } else { newUser = null; } } return(newUser); }
/// <summary> /// Método para crear nuevos usuarios. /// </summary> /// <param name="newUser"></param> /// <returns></returns> public static UserDTO CreateUser(UserDTO newUser) { using(DutiesFamilyEntities dataContext = new DutiesFamilyEntities()) { if(dataContext.User.Count(x=>x.Email.Trim()==newUser.Email.Trim())==0) { var user = new User(); user.Email = newUser.Email; user.Family = dataContext.Family.FirstOrDefault(x => x.IdFamily == newUser.IdFamily); user.IdFamily = newUser.IdFamily; user.Rol = dataContext.Rol.FirstOrDefault(x => x.IdRol == newUser.IdRol); user.IdRol = newUser.IdRol; user.Image = newUser.Image; user.Password = Guid.NewGuid().ToString().Split('-').FirstOrDefault(); user.UserName = newUser.UserName; dataContext.User.Add(user); dataContext.SaveChanges(); newUser.Password = user.Password; } else { newUser = null; } } return newUser; }
/// <summary> /// Método para crear tareas asignadas a la familia. /// </summary> /// <param name="duty"></param> /// <returns></returns> public DutyDto CreateDuty(DutyDto duty) { using (DutiesFamilyEntities dataContext = new DutiesFamilyEntities()) { var dutyCreated = new Duty(); dutyCreated.DutyName = duty.DutyName; dutyCreated.IdFamily = duty.IdFamily; dataContext.Duty.Add(dutyCreated); dataContext.SaveChanges(); } return(duty); }
/// <summary> /// Método para validar la existencia de un usuario. /// </summary> /// <param name="email"></param> /// <returns></returns> public static bool ExistUser(string email) { var response = false; using (DutiesFamilyEntities dataContext = new DutiesFamilyEntities()) { if (dataContext.User.Count(x => x.Email.Trim() == email.Trim()) > 0) { response = true; } } return(response); }
/// <summary> /// Método para validar la existencia de un usuario. /// </summary> /// <param name="email"></param> /// <returns></returns> public static bool ExistUser(string email) { var response = false; using (DutiesFamilyEntities dataContext = new DutiesFamilyEntities()) { if (dataContext.User.Count(x => x.Email.Trim() == email.Trim()) > 0) { response = true; } } return response; }
/// <summary> /// Método para registrar familia. /// </summary> /// <param name="family"></param> /// <returns></returns> public FamilyDto RegisterFamily(FamilyDto family) { using(DutiesFamilyEntities dataContext = new DutiesFamilyEntities()) { var familyCreated = new Family(); familyCreated.FamilyName = family.FamilyName; familyCreated.Image = family.Image; familyCreated.Password = family.Password; dataContext.Family.Add(familyCreated); dataContext.SaveChanges(); family.IdFamily = familyCreated.IdFamily; } return family; }
/// <summary> /// Método para registrar familia. /// </summary> /// <param name="family"></param> /// <returns></returns> public FamilyDto RegisterFamily(FamilyDto family) { using (DutiesFamilyEntities dataContext = new DutiesFamilyEntities()) { var familyCreated = new Family(); familyCreated.FamilyName = family.FamilyName; familyCreated.Image = family.Image; familyCreated.Password = family.Password; dataContext.Family.Add(familyCreated); dataContext.SaveChanges(); family.IdFamily = familyCreated.IdFamily; } return(family); }
/// <summary> /// Método para consultar un nuevo Rol /// </summary> /// <returns></returns> public static List<RolDto> GetRoles() { var roles = new List<RolDto>(); using (DutiesFamilyEntities dataContext = new DutiesFamilyEntities()) { foreach (var item in dataContext.Rol.ToList()) { var rol = new RolDto(); rol.IdRol = item.IdRol; rol.RolName = item.RolName; roles.Add(rol); } } return roles; }
/// <summary> /// Método para consultar un nuevo Rol /// </summary> /// <returns></returns> public static List <RolDto> GetRoles() { var roles = new List <RolDto>(); using (DutiesFamilyEntities dataContext = new DutiesFamilyEntities()) { foreach (var item in dataContext.Rol.ToList()) { var rol = new RolDto(); rol.IdRol = item.IdRol; rol.RolName = item.RolName; roles.Add(rol); } } return(roles); }
/// <summary> /// Método para consultar las tareas creadas por la familia. /// </summary> /// <param name="idFamily"></param> /// <returns></returns> public List <DutyDto> GetDutiesFamily(int idFamily) { var duties = new List <DutyDto>(); using (DutiesFamilyEntities dataContext = new DutiesFamilyEntities()) { foreach (var item in dataContext.Duty.Where(x => x.IdFamily == idFamily).ToList()) { var duty = new DutyDto(); duty.IdDuty = item.IdDuty; duty.IdFamily = item.IdFamily; duty.DutyName = item.DutyName; duties.Add(duty); } } return(duties); }
/// <summary> /// Método para validar que la familia exista. /// </summary> /// <param name="FamilyName"></param> /// <returns></returns> public FamilyDto ValidateFamily(string FamilyName, string password) { var family = new FamilyDto(); using (DutiesFamilyEntities dataContext = new DutiesFamilyEntities()) { if (dataContext.Family.Count(x => x.FamilyName.Trim().Equals(FamilyName.Trim()) && x.Password.Equals(password)) > 0) { var familyQuery = dataContext.Family .FirstOrDefault(x => x.FamilyName.Trim().Equals(FamilyName.Trim()) && x.Password.Equals(password)); family.FamilyName = familyQuery.FamilyName; family.Image = familyQuery.Image; family.IdFamily = familyQuery.IdFamily; } else family = null; } return family; }
/// <summary> /// Método para verificar que la familia este registrada. /// </summary> /// <param name="familyName"></param> /// <returns></returns> public FamilyDto ExistFamily(string familyName) { var family = new FamilyDto(); using (DutiesFamilyEntities dataContext = new DutiesFamilyEntities()) { if (dataContext.Family.Count(x => x.FamilyName.Trim().Equals(familyName.Trim())) > 0) { var familyQuery = dataContext.Family .FirstOrDefault(x => x.FamilyName.Trim().Equals(familyName.Trim())); family.FamilyName = familyQuery.FamilyName; family.Image = familyQuery.Image; family.IdFamily = familyQuery.IdFamily; } else family = null; } return family; }
/// <summary> /// Método para validar que la familia exista. /// </summary> /// <param name="FamilyName"></param> /// <returns></returns> public FamilyDto ValidateFamily(string FamilyName, string password) { var family = new FamilyDto(); using (DutiesFamilyEntities dataContext = new DutiesFamilyEntities()) { if (dataContext.Family.Count(x => x.FamilyName.Trim().Equals(FamilyName.Trim()) && x.Password.Equals(password)) > 0) { var familyQuery = dataContext.Family .FirstOrDefault(x => x.FamilyName.Trim().Equals(FamilyName.Trim()) && x.Password.Equals(password)); family.FamilyName = familyQuery.FamilyName; family.Image = familyQuery.Image; family.IdFamily = familyQuery.IdFamily; } else { family = null; } } return(family); }
/// <summary> /// Método para verificar que la familia este registrada. /// </summary> /// <param name="familyName"></param> /// <returns></returns> public FamilyDto ExistFamily(string familyName) { var family = new FamilyDto(); using (DutiesFamilyEntities dataContext = new DutiesFamilyEntities()) { if (dataContext.Family.Count(x => x.FamilyName.Trim().Equals(familyName.Trim())) > 0) { var familyQuery = dataContext.Family .FirstOrDefault(x => x.FamilyName.Trim().Equals(familyName.Trim())); family.FamilyName = familyQuery.FamilyName; family.Image = familyQuery.Image; family.IdFamily = familyQuery.IdFamily; } else { family = null; } } return(family); }