private void SoftDelete(tblM_Technology technology)
 {
     if (technology != null)
     {
         technology.Status_FK = (int)RecordStatus.Deleted;
     }
 }
 private void HardDelete(tblM_Technology technology)
 {
     if (technology != null)
     {
         Db.tblM_Technology.Remove(technology);
     }
 }
 public void Update(TechnologyDTO technologyDTO, DateTime dateStamp)
 {
     if (technologyDTO == null)
     {
         throw new ArgumentNullException("Technology model is null.");
     }
     tblM_Technology technology = technologyFactory.CreateFromDbAndUpdateFromDTO(technologyDTO, dateStamp);
 }
        public tblM_Technology Insert(TechnologyDTO technologyDTO, DateTime dateStamp)
        {
            if (technologyDTO == null)
            {
                throw new ArgumentNullException("Technology model is null.");
            }
            tblM_Technology technology = technologyFactory.CreateFromDTO(technologyDTO, dateStamp);

            return(Db.tblM_Technology.Add(technology));
        }
Ejemplo n.º 5
0
        public tblM_Technology CreateFromDTO(TechnologyDTO technologyDTO, DateTime dateStamp)
        {
            if (technologyDTO == null)
            {
                throw new ArgumentNullException("Technology model is null.");
            }
            technologyDTO.Status_FK   = (int)RecordStatus.Active;
            technologyDTO.CreatedBy   = User.Username;
            technologyDTO.CreatedDate = dateStamp;
            technologyDTO.UpdatedBy   = User.Username;
            technologyDTO.UpdatedDate = dateStamp;
            tblM_Technology technology = technologyDTO.ToObject <tblM_Technology>();

            return(technology);
        }
        public SaveResult <TechnologyEntryModel> Save(TechnologyDTO technologyDTO, DateTime dateStamp)
        {
            ModelValidationResult validationResult = technologyValidator.Validate(technologyDTO);
            bool success = false;
            TechnologyEntryModel model = null;

            if (validationResult.IsValid)
            {
                tblM_Technology technology = Insert(technologyDTO, dateStamp);
                Db.SaveChanges();

                success = true;
                model   = technologyEntryDataProvider.Get(technology.Technology_PK);
            }

            return(new SaveResult <TechnologyEntryModel>
            {
                Success = success,
                Message = validationResult.IsValid ? "Data successfully created." : "Validation error occured.",
                Model = model,
                ValidationResult = validationResult
            });
        }
        public DeleteResult <tblM_Technology> Execute(int technologyPK, DeleteMethod deleteMethod)
        {
            tblM_Technology technology = Db.tblM_Technology.Find(technologyPK);

            if (technology == null)
            {
                return(new DeleteResult <tblM_Technology>()
                {
                    Success = false,
                    Message = $"Id '{technologyPK}' is not found.",
                    Record = null
                });
            }

            switch (deleteMethod)
            {
            case DeleteMethod.Soft:
                SoftDelete(technology);
                break;

            case DeleteMethod.Hard:
                HardDelete(technology);
                break;

            default:
                break;
            }

            Db.SaveChanges();

            return(new DeleteResult <tblM_Technology>()
            {
                Success = true,
                Message = $"Technology with Id '{technologyPK}' successfully deleted.",
                Record = technology
            });
        }