public void Update(SOWResultDTO sowResultDTO, DateTime dateStamp)
 {
     if (sowResultDTO == null)
     {
         throw new ArgumentNullException("SOWResult model is null.");
     }
     tblT_SOWResult sowResult = sowResultFactory.CreateFromDbAndUpdateFromDTO(sowResultDTO, dateStamp);
 }
Exemple #2
0
        public tblT_SOWResult AddSOWResult(SOWResultDTO sowResultDTO, DateTime dateStamp)
        {
            if (sowResultDTO == null)
            {
                throw new ArgumentNullException("SOWResult model is null.");
            }
            tblT_SOWResult sowResult = sowResultFactory.CreateFromDTO(sowResultDTO, dateStamp);

            return(Db.tblT_SOWResult.Add(sowResult));
        }
        public tblT_SOWResult CreateFromDTO(SOWResultDTO sowResultDTO, DateTime dateStamp)
        {
            if (sowResultDTO == null)
            {
                throw new ArgumentNullException("SOWResult model is null.");
            }
            sowResultDTO.Status_FK   = (int)RecordStatus.Active;
            sowResultDTO.CreatedBy   = User.Username;
            sowResultDTO.CreatedDate = dateStamp;
            sowResultDTO.UpdatedBy   = User.Username;
            sowResultDTO.UpdatedDate = dateStamp;
            tblT_SOWResult sowResult = sowResultDTO.ToObject <tblT_SOWResult>();

            sowResult.FileUrl    = sowResultDTO.FileUrl;
            sowResult.CheckIn_FK = sowResultDTO.CheckIn_FK;
            return(sowResult);
        }
Exemple #4
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
            });
        }
        public tblT_SOWResult CreateFromDbAndUpdateFromDTO(SOWResultDTO sowResultDTO, DateTime dateStamp)
        {
            tblT_SOWResult sowResult;

            if (sowResultDTO == null)
            {
                throw new ArgumentNullException("SOWResult model is null.");
            }
            sowResult = Db.tblT_SOWResult.FirstOrDefault(x => x.CheckIn_FK == sowResultDTO.CheckIn_FK);
            if (sowResult == null)
            {
                throw new KairosException($"Cannot make approval for this task, because user not yet submit the file/url.");
            }

            //if (sowResultDTO.IsApproved == null)
            //    throw new KairosException($"'isApproved' parameter is required, please fill it with 'true' or 'false'.");

            sowResult.UpdateValueFrom(sowResultDTO, "SOWResult_PK", "Status_FK", "FileUrl");
            sowResultDTO.CreatedBy   = sowResult.CreatedBy;
            sowResultDTO.CreatedDate = sowResult.CreatedDate;
            sowResult.UpdatedBy      = sowResultDTO.UpdatedBy = User.Username;
            sowResult.UpdatedDate    = sowResultDTO.UpdatedDate = dateStamp;
            sowResult.IsApproved     = sowResultDTO.IsApproved;

            if (sowResult.IsApproved != null)
            {
                sowResult.ApprovedDate = dateStamp;
                sowResult.ApprovedBy   = User.Username;
            }
            else
            {
                sowResult.FileUrl = sowResultDTO.FileUrl;
            }
            sowResult.CheckIn_FK = sowResultDTO.CheckIn_FK;
            return(sowResult);
        }
        public SOWResultDTO GetByCheckinFK(int checkinFK)
        {
            SOWResultDTO record = GetQuery().FirstOrDefault(sowResult => sowResult.CheckIn_FK == checkinFK);

            return(record);
        }
        public SOWResultDTO GetByPrimaryKey(int primaryKey)
        {
            SOWResultDTO record = GetQuery().FirstOrDefault(sowResult => sowResult.SOWResult_PK == primaryKey);

            return(record);
        }