Beispiel #1
0
        public async Task <HttpResponseMessage> GetCarInfo([FromUri] UpdateChargeRequest request)
        {
            logInfo.Info(string.Format("【收费服务】获取车辆信息接口请求串:{0}", Request.RequestUri));
            CarChargeViewModel viewModel = new CarChargeViewModel();

            if (!ModelState.IsValid)
            {
                viewModel.BusinessStatus = -10000;
                string msg = ModelState.Values.Where(item => item.Errors.Count == 1).Aggregate(string.Empty, (current, item) => current + (item.Errors[0].ErrorMessage + ";   "));
                viewModel.StatusMessage = "输入参数错误," + msg;
                return(viewModel.ResponseToJson());
            }
            if (!request.LicenseNo.IsValidLicenseno())
            {
                viewModel.BusinessStatus = -10000;
                viewModel.StatusMessage  = "参数校验错误,请检查车牌号";
                return(viewModel.ResponseToJson());
            }
            try
            {
                var response = await _chargeService.Update(request, Request.GetQueryNameValuePairs());

                if (response.Status == HttpStatusCode.BadRequest || response.Status == HttpStatusCode.Forbidden)
                {
                    viewModel.BusinessStatus = -10001;
                    viewModel.StatusMessage  = "参数校验错误,请检查您的校验码";
                    return(viewModel.ResponseToJson());
                }
                if (response.Status == HttpStatusCode.ExpectationFailed)
                {
                    viewModel.BusinessStatus = -10003;
                    viewModel.StatusMessage  = "服务发生异常";
                }
                else
                {
                    if (response.ErrCode == 0)
                    {
                        viewModel.Item           = response.ConvertToViewModel();
                        viewModel.BusinessStatus = 1;
                    }
                    else if (response.ErrCode == -2)
                    {
                        viewModel.BusinessStatus = 2;//余额不足
                    }
                    else if (response.ErrCode == -1)
                    {
                        viewModel.BusinessStatus = 3;//没有获取到
                    }
                }
            }
            catch (Exception ex)
            {
                logError.Info("发生异常:" + ex.Source + "\n" + ex.StackTrace + "\n" + ex.Message + "\n" + ex.InnerException);
            }

            return(viewModel.ResponseToJson());
        }
Beispiel #2
0
        public ActionResult Post(Charge vm)
        {
            Charge pt = vm;

            if (ModelState.IsValid)
            {
                if (vm.ChargeId <= 0)
                {
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    _ChargeService.Create(pt);

                    ActivityLog log = new ActivityLog()
                    {
                        ActivityType = (int)(ActivityTypeContants.Added),
                        CreatedBy    = User.Identity.Name,
                        CreatedDate  = DateTime.Now,
                        DocId        = pt.ChargeId,
                        Narration    = "A new Charge is created with the Id " + pt.ChargeId,
                    };

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        return(View("Create", vm));
                    }


                    return(RedirectToAction("Create").Success("Data saved successfully"));
                }
                else
                {
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                    Charge temp  = _ChargeService.Find(pt.ChargeId);
                    Charge ExRec = Mapper.Map <Charge>(temp);

                    temp.ChargeName   = pt.ChargeName;
                    temp.ChargeCode   = pt.ChargeCode;
                    temp.IsActive     = pt.IsActive;
                    temp.ModifiedDate = DateTime.Now;
                    temp.ModifiedBy   = User.Identity.Name;
                    temp.ObjectState  = Model.ObjectState.Modified;
                    _ChargeService.Update(temp);

                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = ExRec,
                        Obj   = temp,
                    });

                    XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        return(View("Create", pt));
                    }

                    //LogActivity.LogActivityDetail(new DocumentTypeService(_unitOfWork).Find(MasterDocTypeConstants.Charge).DocumentTypeId,
                    //temp.ChargeId,
                    //null,
                    //(int)ActivityTypeContants.Modified,
                    //"",
                    //User.Identity.Name, temp.ChargeName, Modifications);

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.Charge).DocumentTypeId,
                        DocId           = temp.ChargeId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        xEModifications = Modifications,
                    }));

                    return(RedirectToAction("Index").Success("Data saved successfully"));
                }
            }
            return(View("Create", vm));
        }