コード例 #1
0
        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
            };
        }
コード例 #2
0
 public void Update(PositionDTO positionDTO, DateTime dateStamp)
 {
     if (positionDTO == null)
     {
         throw new ArgumentNullException("Position model is null.");
     }
     tblM_Position position = positionFactory.CreateFromDbAndUpdateFromDTO(positionDTO, dateStamp);
 }
コード例 #3
0
        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));
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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
            });
        }
コード例 #6
0
 private void SoftDelete(tblM_Position position)
 {
     if (position != null)
         position.Status_FK = (int)RecordStatus.Deleted;
 }
コード例 #7
0
 private void HardDelete(tblM_Position position)
 {
     if (position != null)
         Db.tblM_Position.Remove(position);
 }