Example #1
0
 public void Update(SOWIssueDTO sowIssueDTO, DateTime dateStamp)
 {
     if (sowIssueDTO == null)
     {
         throw new ArgumentNullException("SOWIssue model is null.");
     }
     tblT_SOWIssue sowIssue = sowIssueFactory.CreateFromDbAndUpdateFromDTO(sowIssueDTO, dateStamp);
 }
Example #2
0
        public tblT_SOWIssue Insert(SOWIssueDTO sowIssueDTO, DateTime dateStamp)
        {
            if (sowIssueDTO == null)
            {
                throw new ArgumentNullException("SOWIssue model is null.");
            }
            tblT_SOWIssue sowIssue = sowIssueFactory.CreateFromDTO(sowIssueDTO, dateStamp);

            return(Db.tblT_SOWIssue.Add(sowIssue));
        }
        private SOWIssueEntryModel GetCreateStateModel()
        {
            SOWIssueEntryFormData formData     = new SOWIssueEntryFormData();
            List <Control>        formControls = CreateFormControls(0);
            SOWIssueDTO           sowIssueDTO  = new SOWIssueDTO();

            return(new SOWIssueEntryModel()
            {
                FormData = formData,
                FormControls = formControls,
                Model = sowIssueDTO,
            });
        }
        private SOWIssueEntryModel GetUpdateStateModel(int sowIssuePK)
        {
            SOWIssueEntryFormData formData     = new SOWIssueEntryFormData();
            List <Control>        formControls = CreateFormControls(sowIssuePK);
            SOWIssueDTO           sowIssueDTO  = sowIssueQuery.GetByPrimaryKey(sowIssuePK);

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

            return(new SOWIssueEntryModel()
            {
                FormData = formData,
                FormControls = formControls,
                Model = sowIssueDTO,
            });
        }
Example #5
0
        public IHttpActionResult Update([FromBody] SOWIssueDTO sowIssue)
        {
            string accessType = "";

            ThrowIfUserHasNoRole(accessType);
            if (sowIssue == null)
            {
                throw new KairosException("Missing model parameter");
            }

            if (sowIssue.SOWIssue_PK == 0)
            {
                throw new KairosException("Put method is not allowed because the requested primary key is '0' (zero) .");
            }

            using (var sowIssueUpdateHandler = new SOWIssueUpdateHandler(Db, ActiveUser, new SOWIssueValidator(), new SOWIssueFactory(Db, ActiveUser), new SOWIssueQuery(Db), AccessControl))
            {
                using (var transaction = new TransactionScope())
                {
                    var saveResult = sowIssueUpdateHandler.Save(sowIssue, DateTime.Now);
                    transaction.Complete();
                    if (saveResult.Success)
                    {
                        return(Ok(new
                        {
                            issueId = saveResult.Model.Model.SOWIssue_PK,
                            success = true,
                            msg = "Update laporan kendala berhasil."
                        }));
                    }
                    return(Ok(new
                    {
                        status = false,
                        msg = saveResult.ValidationResult.Errors.Count > 0 ? saveResult.ValidationResult.Errors[0].Message : saveResult.Message,
                        validationResult = saveResult.ValidationResult
                    }));
                }
            }
        }
Example #6
0
        public SaveResult <SOWIssueEntryModel> Save(SOWIssueDTO sowIssueDTO, DateTime dateStamp)
        {
            ModelValidationResult validationResult = sowIssueValidator.Validate(sowIssueDTO);
            bool success             = false;
            SOWIssueEntryModel model = null;

            if (validationResult.IsValid)
            {
                success = true;
                Update(sowIssueDTO, dateStamp);
                Db.SaveChanges();
                model = sowIssueEntryDataProvider.Get(sowIssueDTO.SOWIssue_PK);
            }

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

            return(record);
        }