Beispiel #1
0
        public SaveResult <SOWResultEntryModel> Save(SOWResultDTO sowResultDTO, DateTime dateStamp)
        {
            ModelValidationResult validationResult = sowResultValidator.Validate(sowResultDTO);
            bool success = false;
            SOWResultEntryModel model = null;

            if (validationResult.IsValid)
            {
                var result = Db.tblT_SOWResult.FirstOrDefault(x => x.CheckIn_FK == sowResultDTO.CheckIn_FK);

                if (result != null && result.IsApproved != null)
                {
                    var approval = result.IsApproved.Value == true ? "approved" : "rejected";
                    throw new Kairos.KairosException($"This task is already {approval}");
                }

                tblT_SOWResult sowResult = null;
                if (result == null)
                {
                    sowResult = AddSOWResult(sowResultDTO, dateStamp);
                }
                else
                {
                    sowResult = Update(sowResultDTO, dateStamp);
                }
                Db.SaveChanges();

                success = true;
                model   = sowResultEntryDataProvider.Get(sowResult.SOWResult_PK);
            }

            return(new SaveResult <SOWResultEntryModel>
            {
                Success = success,
                Message = validationResult.IsValid ? "Data successfully created." : "Validation error occured.",
                Model = model,
                ValidationResult = validationResult
            });
        }
        public SaveResult <SOWResultEntryModel> Save(SOWResultDTO sowResultDTO, DateTime dateStamp)
        {
            ModelValidationResult validationResult = sowResultValidator.Validate(sowResultDTO);
            bool success = false;
            SOWResultEntryModel model = null;

            if (validationResult.IsValid)
            {
                success = true;
                Update(sowResultDTO, dateStamp);
                Db.SaveChanges();
                model = sowResultEntryDataProvider.Get(sowResultDTO.SOWResult_PK);
            }

            return(new SaveResult <SOWResultEntryModel>
            {
                Success = success,
                Message = validationResult.IsValid ? "Data successfully updated." : "Validation error occured.",
                Model = model,
                ValidationResult = validationResult
            });
        }