コード例 #1
0
        /// <summary>
        /// Get Detail of Kpi group.
        /// </summary>
        /// <param name="id">The identity of Kpi group.</param>
        /// <returns></returns>
        public KpiGroupViewModel GetDetail(int id)
        {
            var result = new KpiGroupViewModel();
            var data   = _unitOfWork.GetRepository <KpiGroup>().GetCache(x => x.Id == id).FirstOrDefault();

            result = _mapper.Map <KpiGroup, KpiGroupViewModel>(data);
            result.SapScoreField = _unitOfWork.GetRepository <SapFields>().GetCache(x => x.Id == data.SapFieldsId).FirstOrDefault()?.SapFields1;
            result.KpiGroupItems = this.GetKpiGroupItem(id).ToList();
            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Validate kpi group any duplicate item.
        /// </summary>
        /// <param name="model">The kpi group information.</param>
        /// <returns></returns>
        public ResultViewModel ValidateDuplicatesItems(KpiGroupViewModel model)
        {
            var result     = new ResultViewModel();
            var duplicates = model.KpiGroupItems.GroupBy(s => s).SelectMany(grp => grp.Skip(1));

            if (duplicates.Count() > 0)
            {
                result = UtilityService.InitialResultError(MessageValue.KpiGroupItemsDuplicates, (int)System.Net.HttpStatusCode.BadRequest);
            }
            return(result);
        }
コード例 #3
0
        /// <summary>
        /// Validate Data before insert and update kpi group.
        /// </summary>
        /// <param name="model">The kpi group information.</param>
        /// <returns></returns>
        public ResultViewModel ValidateData(KpiGroupViewModel model)
        {
            var result    = new ResultViewModel();
            var sapFields = _unitOfWork.GetRepository <SapFields>().GetCache(x => !x.IsUse).FirstOrDefault();

            if (sapFields == null)
            {
                result = UtilityService.InitialResultError(MessageValue.KpiGroupOverFiftySapFields, (int)System.Net.HttpStatusCode.BadRequest);
            }
            result = this.ValidateDuplicatesItems(model);
            return(result);
        }
コード例 #4
0
        public IActionResult Save([FromBody] KpiGroupViewModel model)
        {
            IActionResult response;
            var           result = _kpiGroup.ValidateData(model);

            if (result.IsError)
            {
                response = BadRequest(result);
            }
            else
            {
                response = Ok(_kpiGroup.Save(model));
            }
            return(response);
        }
コード例 #5
0
        /// <summary>
        /// Insert new Kpi group.
        /// </summary>
        /// <param name="model">The Kpi information value.</param>
        /// <returns></returns>
        public ResultViewModel Save(KpiGroupViewModel model)
        {
            var result = new ResultViewModel();

            using (TransactionScope scope = new TransactionScope())
            {
                var kpiGroup = _mapper.Map <KpiGroupViewModel, KpiGroup>(model);
                kpiGroup.SapFieldsId         = this.GetSapFields();
                kpiGroup.CreateBy            = _token.EmpNo;
                kpiGroup.CreateDate          = DateTime.Now;
                kpiGroup.CreateByPurchaseOrg = _token.PurchasingOrg[0];
                _unitOfWork.GetRepository <KpiGroup>().Add(kpiGroup);
                _unitOfWork.Complete();
                this.SaveItem(kpiGroup.Id, model.KpiGroupItems);
                _unitOfWork.Complete(scope);
            }
            this.ReloadCacheKpiGroup();
            return(result);
        }
コード例 #6
0
        public IActionResult Edit([FromBody] KpiGroupViewModel model)
        {
            IActionResult response;
            var           result = _kpiGroup.ValidateDuplicatesItems(model);

            if (result.IsError)
            {
                response = BadRequest(result);
            }
            else if (_kpiGroup.IsUse(model.Id))
            {
                response = BadRequest(UtilityService.InitialResultError(string.Format(MessageValue.IsUseMessageFormat, MessageValue.KpiMessage),
                                                                        (int)System.Net.HttpStatusCode.BadRequest));
            }
            else
            {
                response = Ok(_kpiGroup.Edit(model));
            }
            return(response);
        }
コード例 #7
0
        /// <summary>
        /// Update Kpi group.
        /// </summary>
        /// <param name="model">The Kpi information value.</param>
        /// <returns></returns>
        public ResultViewModel Edit(KpiGroupViewModel model)
        {
            var result = new ResultViewModel();

            using (TransactionScope scope = new TransactionScope())
            {
                var kpiGroup = _unitOfWork.GetRepository <KpiGroup>().GetCache(x => x.Id == model.Id).FirstOrDefault();
                kpiGroup.KpiGroupNameTh      = model.KpiGroupNameTh;
                kpiGroup.KpiGroupNameEn      = model.KpiGroupNameEn;
                kpiGroup.KpiGroupShortTextTh = model.KpiGroupShortTextTh;
                kpiGroup.KpiGroupShortTextEn = model.KpiGroupShortTextEn;
                kpiGroup.LastModifyBy        = _token.EmpNo;
                kpiGroup.LastModifyDate      = DateTime.Now;
                _unitOfWork.GetRepository <KpiGroup>().Update(kpiGroup);
                this.EditItem(kpiGroup.Id, model.KpiGroupItems);
                _unitOfWork.Complete(scope);
            }
            this.ReloadCacheKpiGroup();
            return(result);
        }