public DeleteResult<tblM_Position> Execute(int positionPK, DeleteMethod deleteMethod) { tblM_Position position = Db.tblM_Position.Find(positionPK); if (position == null) { return new DeleteResult<tblM_Position>() { Success = false, Message = $"Id '{positionPK}' is not found.", Record = null }; } switch (deleteMethod) { case DeleteMethod.Soft: SoftDelete(position); break; case DeleteMethod.Hard: HardDelete(position); break; default: break; } Db.SaveChanges(); return new DeleteResult<tblM_Position>() { Success = true, Message = $"Position with Id '{positionPK}' successfully deleted.", Record = position }; }
public void Update(PositionDTO positionDTO, DateTime dateStamp) { if (positionDTO == null) { throw new ArgumentNullException("Position model is null."); } tblM_Position position = positionFactory.CreateFromDbAndUpdateFromDTO(positionDTO, dateStamp); }
public tblM_Position Insert(PositionDTO positionDTO, DateTime dateStamp) { if (positionDTO == null) { throw new ArgumentNullException("Position model is null."); } tblM_Position position = positionFactory.CreateFromDTO(positionDTO, dateStamp); return(Db.tblM_Position.Add(position)); }
public tblM_Position CreateFromDTO(PositionDTO positionDTO, DateTime dateStamp) { if (positionDTO == null) { throw new ArgumentNullException("Position model is null."); } positionDTO.Status_FK = (int)RecordStatus.Active; positionDTO.CreatedBy = User.Username; positionDTO.CreatedDate = dateStamp; positionDTO.UpdatedBy = User.Username; positionDTO.UpdatedDate = dateStamp; tblM_Position position = positionDTO.ToObject <tblM_Position>(); return(position); }
public SaveResult <PositionEntryModel> Save(PositionDTO positionDTO, DateTime dateStamp) { ModelValidationResult validationResult = positionValidator.Validate(positionDTO); bool success = false; PositionEntryModel model = null; if (validationResult.IsValid) { tblM_Position position = Insert(positionDTO, dateStamp); Db.SaveChanges(); success = true; model = positionEntryDataProvider.Get(position.Position_PK); } return(new SaveResult <PositionEntryModel> { Success = success, Message = validationResult.IsValid ? "Data successfully created." : "Validation error occured.", Model = model, ValidationResult = validationResult }); }
private void SoftDelete(tblM_Position position) { if (position != null) position.Status_FK = (int)RecordStatus.Deleted; }
private void HardDelete(tblM_Position position) { if (position != null) Db.tblM_Position.Remove(position); }