public String StaffAdd(StaffModel staff) { String Status = String.Empty; try { Staff staffDestination = SetStaff(staff); using (Quadra_TechnologyEntities db = new Quadra_TechnologyEntities()) { Status = staff.name + " " + staff.lastname; staffDestination.StaffId = Guid.NewGuid(); staffDestination.CreatedOn = staffDestination.ModifyOn; staffDestination.DepartmentID = db.Department.Where(w => w.DepartmentName == staff.department).Select(s => s.DepartmentID).FirstOrDefault(); db.Entry(staffDestination).State = System.Data.Entity.EntityState.Added; db.SaveChanges(); db.Dispose(); } Status = "Create profile " + Status + " success..."; } catch (Exception ex) { Status = Error_handle(ex); } return(Status); }
public String StaffDelete(Guid id) { String Status = String.Empty; try { Staff staffDestination = new Staff { StaffId = id }; using (Quadra_TechnologyEntities db = new Quadra_TechnologyEntities()) { Status = db.Staff.Where(w => w.StaffId.Equals(id)).Select(s => new { fullname = s.StaffName + " " + s.StaffLastName }).FirstOrDefault().ToString(); db.Entry(staffDestination).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); db.Dispose(); } Status = "Deleted " + Status + " success..."; } catch (Exception ex) { Status = Error_handle(ex); } return(Status); }