private void SoftDelete(tblM_CostKategori costKategori)
 {
     if (costKategori != null)
     {
         costKategori.Status_FK = (int)RecordStatus.Deleted;
     }
 }
 private void HardDelete(tblM_CostKategori costKategori)
 {
     if (costKategori != null)
     {
         Db.tblM_CostKategori.Remove(costKategori);
     }
 }
 public void Update(CostKategoriDTO costKategoriDTO, DateTime dateStamp)
 {
     if (costKategoriDTO == null)
     {
         throw new ArgumentNullException("CostKategori model is null.");
     }
     tblM_CostKategori costKategori = costKategoriFactory.CreateFromDbAndUpdateFromDTO(costKategoriDTO, dateStamp);
 }
        public tblM_CostKategori Insert(CostKategoriDTO costKategoriDTO, DateTime dateStamp)
        {
            if (costKategoriDTO == null)
            {
                throw new ArgumentNullException("CostKategori model is null.");
            }
            tblM_CostKategori costKategori = costKategoriFactory.CreateFromDTO(costKategoriDTO, dateStamp);

            return(Db.tblM_CostKategori.Add(costKategori));
        }
示例#5
0
        public tblM_CostKategori CreateFromDTO(CostKategoriDTO costKategoriDTO, DateTime dateStamp)
        {
            if (costKategoriDTO == null)
            {
                throw new ArgumentNullException("CostKategori model is null.");
            }
            costKategoriDTO.Status_FK   = (int)RecordStatus.Active;
            costKategoriDTO.CreatedBy   = User.Username;
            costKategoriDTO.CreatedDate = dateStamp;
            costKategoriDTO.UpdatedBy   = User.Username;
            costKategoriDTO.UpdatedDate = dateStamp;
            tblM_CostKategori costKategori = costKategoriDTO.ToObject <tblM_CostKategori>();

            return(costKategori);
        }
        public SaveResult <CostKategoriEntryModel> Save(CostKategoriDTO costKategoriDTO, DateTime dateStamp)
        {
            ModelValidationResult validationResult = costKategoriValidator.Validate(costKategoriDTO);
            bool success = false;
            CostKategoriEntryModel model = null;

            if (validationResult.IsValid)
            {
                tblM_CostKategori costKategori = Insert(costKategoriDTO, dateStamp);
                Db.SaveChanges();

                success = true;
                model   = costKategoriEntryDataProvider.Get(costKategori.CostKategori_PK);
            }

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

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

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

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

            default:
                break;
            }

            Db.SaveChanges();

            return(new DeleteResult <tblM_CostKategori>()
            {
                Success = true,
                Message = $"CostKategori with Id '{costKategoriPK}' successfully deleted.",
                Record = costKategori
            });
        }