Beispiel #1
0
        public IHttpActionResult Create([FromBody] CostKategoriDTO costKategori)
        {
            ThrowIfUserHasNoRole(createRole);
            if (costKategori == null)
            {
                throw new KairosException("Missing model parameter");
            }

            if (costKategori.CostKategori_PK != 0)
            {
                throw new KairosException("Post method is not allowed because the requested primary key is must be '0' (zero) .");
            }
            using (var costKategoriCreateHandler = new CostKategoriCreateHandler(Db, ActiveUser, new CostKategoriValidator(), new CostKategoriFactory(Db, ActiveUser), new CostKategoriQuery(Db), AccessControl))
            {
                using (var transaction = new TransactionScope())
                {
                    var saveResult = costKategoriCreateHandler.Save(costKategoriDTO: costKategori, dateStamp: DateTime.Now);
                    transaction.Complete();
                    if (saveResult.Success)
                    {
                        return(Ok(new SuccessResponse(saveResult.Model, saveResult.Message)));
                    }
                    return(Ok(new ErrorResponse(ServiceStatusCode.ValidationError, saveResult.ValidationResult, saveResult.Message)));
                }
            }
        }
 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));
        }
Beispiel #4
0
        private CostKategoriEntryModel GetCreateStateModel()
        {
            CostKategoriEntryFormData formData        = new CostKategoriEntryFormData();
            List <Control>            formControls    = CreateFormControls(0);
            CostKategoriDTO           costKategoriDTO = new CostKategoriDTO();

            return(new CostKategoriEntryModel()
            {
                FormData = formData,
                FormControls = formControls,
                Model = new CostKategoriDTO(),
            });
        }
Beispiel #5
0
        private CostKategoriEntryModel GetUpdateStateModel(int costKategoriPK)
        {
            CostKategoriEntryFormData formData        = new CostKategoriEntryFormData();
            List <Control>            formControls    = CreateFormControls(costKategoriPK);
            CostKategoriDTO           costKategoriDTO = costKategoriQuery.GetByPrimaryKey(costKategoriPK);

            if (costKategoriDTO == null)
            {
                throw new KairosException($"Record with primary key '{costKategoriDTO.CostKategori_PK}' is not found.");
            }

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

            if (validationResult.IsValid)
            {
                success = true;
                Update(costKategoriDTO, dateStamp);
                Db.SaveChanges();
                model = costKategoriEntryDataProvider.Get(costKategoriDTO.CostKategori_PK);
            }

            return(new SaveResult <CostKategoriEntryModel>
            {
                Success = success,
                Message = validationResult.IsValid ? "Data successfully updated." : "Validation error occured.",
                Model = model,
                ValidationResult = validationResult
            });
        }
        public CostKategoriDTO GetByPrimaryKey(int primaryKey)
        {
            CostKategoriDTO record = GetQuery().FirstOrDefault(costKategori => costKategori.CostKategori_PK == primaryKey);

            return(record);
        }