public StaffEntity Create(StaffEntity model) { var staff = _context.staff.Where(x => x.username == model.username || x.email == model.email).FirstOrDefault(); if (staff == null) { model.id = Guid.NewGuid(); model.deleted_at = null; model.password = StringToMD5(model.password); _context.staff.Add(model); _context.SaveChanges(); model.password = null; return(model); } else { if (staff.username == model.username) { throw new Exception("Username already exists"); } else if (staff.email == model.email) { throw new Exception("Email already exists"); } else { throw new Exception("Username and Email already exists"); } } }
public StaffEntity Update(Guid id, StaffEntity modelUpdate) { var data = _context.staff.Find(id); data.firstname = modelUpdate.firstname; data.lastname = modelUpdate.lastname; data.is_active = modelUpdate.is_active; //data.created_by = modelUpdate.created_by; //data.created_at = modelUpdate.created_at; data.updated_at = DateTime.Now; _context.SaveChanges(); return(data); }