public IHttpActionResult Create([FromBody] AsetKategoriDTO asetKategori)
        {
            ThrowIfUserHasNoRole(createRole);
            if (asetKategori == null)
            {
                throw new KairosException("Missing model parameter");
            }

            if (asetKategori.AsetKategori_PK != 0)
            {
                throw new KairosException("Post method is not allowed because the requested primary key is must be '0' (zero) .");
            }
            using (var asetKategoriCreateHandler = new AsetKategoriCreateHandler(Db, ActiveUser, new AsetKategoriValidator(), new AsetKategoriFactory(Db, ActiveUser), new AsetKategoriQuery(Db), AccessControl))
            {
                using (var transaction = new TransactionScope())
                {
                    var saveResult = asetKategoriCreateHandler.Save(asetKategoriDTO: asetKategori, 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)));
                }
            }
        }
Пример #2
0
 public void Update(AsetKategoriDTO asetKategoriDTO, DateTime dateStamp)
 {
     if (asetKategoriDTO == null)
     {
         throw new ArgumentNullException("AsetKategori model is null.");
     }
     tblM_AsetKategori asetKategori = asetKategoriFactory.CreateFromDbAndUpdateFromDTO(asetKategoriDTO, dateStamp);
 }
        public tblM_AsetKategori Insert(AsetKategoriDTO asetKategoriDTO, DateTime dateStamp)
        {
            if (asetKategoriDTO == null)
            {
                throw new ArgumentNullException("AsetKategori model is null.");
            }
            tblM_AsetKategori asetKategori = asetKategoriFactory.CreateFromDTO(asetKategoriDTO, dateStamp);

            return(Db.tblM_AsetKategori.Add(asetKategori));
        }
        private AsetKategoriEntryModel GetCreateStateModel()
        {
            AsetKategoriEntryFormData formData        = new AsetKategoriEntryFormData();
            List <Control>            formControls    = CreateFormControls(0);
            AsetKategoriDTO           asetKategoriDTO = new AsetKategoriDTO();

            return(new AsetKategoriEntryModel()
            {
                FormData = formData,
                FormControls = formControls,
                Model = new AsetKategoriDTO(),
            });
        }
        private AsetKategoriEntryModel GetUpdateStateModel(int asetKategoriPK)
        {
            AsetKategoriEntryFormData formData        = new AsetKategoriEntryFormData();
            List <Control>            formControls    = CreateFormControls(asetKategoriPK);
            AsetKategoriDTO           asetKategoriDTO = asetKategoriQuery.GetByPrimaryKey(asetKategoriPK);

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

            return(new AsetKategoriEntryModel()
            {
                FormData = formData,
                FormControls = formControls,
                Model = asetKategoriDTO,
            });
        }
Пример #6
0
        public SaveResult <AsetKategoriEntryModel> Save(AsetKategoriDTO asetKategoriDTO, DateTime dateStamp)
        {
            ModelValidationResult validationResult = asetKategoriValidator.Validate(asetKategoriDTO);
            bool success = false;
            AsetKategoriEntryModel model = null;

            if (validationResult.IsValid)
            {
                success = true;
                Update(asetKategoriDTO, dateStamp);
                Db.SaveChanges();
                model = asetKategoriEntryDataProvider.Get(asetKategoriDTO.AsetKategori_PK);
            }

            return(new SaveResult <AsetKategoriEntryModel>
            {
                Success = success,
                Message = validationResult.IsValid ? "Data successfully updated." : "Validation error occured.",
                Model = model,
                ValidationResult = validationResult
            });
        }
Пример #7
0
        public AsetKategoriDTO GetByPrimaryKey(int primaryKey)
        {
            AsetKategoriDTO record = GetQuery().FirstOrDefault(asetKategori => asetKategori.AsetKategori_PK == primaryKey);

            return(record);
        }