Ejemplo n.º 1
0
        public ActionResult Add(CourierCompany model)
        {
            using (CTSContext context = new CTSContext())
            {
                context.CourierCompanys.Add(model);
                context.SaveChanges();

                return Json(new AjaxResult("添加成功", AjaxResultType.Success));
            }
        }
        public IActionResult AddOrder([FromBody] JObject data, [FromServices] CourierCompanyService courierCompanyService)
        {
            Order   order;
            Address senderAddress, recipientAddress;

            try
            {
                DateTime date        = DateTime.Now;
                string   paymentType = data["paymentType"].ToObject <string>();

                int    userId     = ((User)HttpContext.Items["User"]).Id;
                User   sender     = userService.GetUser(userId);
                string senderName = sender.FirstName + " " + sender.LastName;

                int        packageId        = data["packageId"].ToObject <int>();
                int        courierCompanyId = data["courierCompanyId"].ToObject <int>();
                List <int> serviceIds       = data["services"].Values <int>().ToList();

                CourierCompany company  = courierCompanyService.GetCourierCompany(courierCompanyId);
                List <Service> services = company.Services.FindAll(s => serviceIds.Contains(s.Id));
                Package        package  = company.Packages.Find(p => p.Id == packageId);

                string recipientName = data["recipientName"].ToObject <string>();
                recipientAddress = data["recipientAddress"].ToObject <Address>();
                senderAddress    = data["senderAddress"].ToObject <Address>();

                Type vatType = Type.GetType("JiperBackend.Strategy." + configuration.GetValue <string>("VATCalculator"));
                order = new Order(date, paymentType, package, senderName, senderAddress, recipientName, recipientAddress, services, (IPriceCalculator)Activator.CreateInstance(vatType));

                userService.AddOrder(userId, order);
            }
            catch (NullReferenceException ex)
            {
                logger.LogException(ex);
                return(BadRequest());
            }
            catch (ArgumentNullException ex)
            {
                logger.LogException(ex);
                return(NotFound());
            }
            catch (FormatException ex)
            {
                logger.LogException(ex);
                return(NotFound());
            }
            return(Ok(order));
        }
Ejemplo n.º 3
0
 public ActionResult Edit(CourierCompany model)
 {
     using (CTSContext context = new CTSContext())
     {
         var courierCompany = context.CourierCompanys.FirstOrDefault(p => p.Id == model.Id);
         courierCompany.ContactMobilePhone = model.ContactMobilePhone;
         courierCompany.ContactName = model.ContactName;
         courierCompany.ContactPhone = model.ContactPhone;
         courierCompany.CourierCode = model.CourierCode;
         courierCompany.CourierName = model.CourierName;
         courierCompany.IsSendSMS = model.IsSendSMS;
         courierCompany.Remark = model.Remark;
         context.SaveChanges();
         return Json(new AjaxResult("编辑成功", AjaxResultType.Success));
     }
 }