public string DeleteRegisterPosition(int id) { try { ManageRegisterPosition MRegisterPosition = new ManageRegisterPosition(); MRegisterPosition = Context.ManageRegisterPosition.Where(x => x.Id == id).FirstOrDefault(); Context.ManageRegisterPosition.Remove(MRegisterPosition); Context.SaveChanges(); return("success"); } catch (Exception e) { throw e; } }
public string EditRegisterPosition(PositionDTO position) { try { ManageRegisterPosition MRegisterPosition = new ManageRegisterPosition(); MRegisterPosition = Context.ManageRegisterPosition.Where(x => x.Id == position.id).FirstOrDefault(); MRegisterPosition.NumberOfPosition = position.NumberOfPosition; MRegisterPosition.ActiveStatus = position.Active; MRegisterPosition.UpdBy = position.Username; MRegisterPosition.UpdDate = DateTime.Now; MRegisterPosition.TypeEmployee = position.Type_Employee; Context.ManageRegisterPosition.Update(MRegisterPosition); Context.SaveChanges(); return("success"); } catch (Exception e) { throw e; } }
public string AddRegisterPosition(PositionDTO position) { try { List <PositionDTO> data = ( from typeEmployee in Context.ManageRegisterPosition where typeEmployee.PositionId == position.PositionId select new PositionDTO { Type_Employee = typeEmployee.TypeEmployee }).ToList(); for (int i = 0; i < data.Count; i++) { if (data[i].Type_Employee == position.Type_Employee) { return("warning"); } } ManageRegisterPosition MRegisterPosition = new ManageRegisterPosition(); MRegisterPosition.PositionId = position.PositionId; MRegisterPosition.NumberOfPosition = position.NumberOfPosition; MRegisterPosition.ActiveStatus = position.Active; MRegisterPosition.CrBy = position.Username; MRegisterPosition.CrDate = DateTime.Now; MRegisterPosition.UpdBy = position.Username; MRegisterPosition.UpdDate = DateTime.Now; MRegisterPosition.TypeEmployee = position.Type_Employee; Context.ManageRegisterPosition.Add(MRegisterPosition); Context.SaveChanges(); return("success"); } catch (Exception e) { throw e; } }