예제 #1
0
        public ActionResult Edit(WardViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (Request["Submit"] == "Save")
                {
                    var Ward = WardService.Get(model.Id);
                    AutoMapper.Mapper.Map(model, Ward);
                    SetModifier(Ward, true);
                    WardService.Update(Ward);

                    TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.UpdateSuccess;
                    if (Request["IsPopup"] != null && Request["IsPopup"].ToString().ToLower().Equals("true"))
                    {
                        return(RedirectToAction("_ClosePopup", "Home", new { area = "", FunctionCallback = "ClosePopupAndReloadPage" }));
                    }
                    return(RedirectToAction("Index"));
                }

                return(View(model));
            }

            return(View(model));

            //if (Request.UrlReferrer != null)
            //    return Redirect(Request.UrlReferrer.AbsoluteUri);
            //return RedirectToAction("Index");
        }
        public async Task <WardDetail_WardDTO> Get([FromBody] WardDetail_WardDTO WardDetail_WardDTO)
        {
            if (!ModelState.IsValid)
            {
                throw new MessageException(ModelState);
            }

            Ward Ward = await WardService.Get(WardDetail_WardDTO.Id);

            return(new WardDetail_WardDTO(Ward));
        }
예제 #3
0
        public async Task <BaseResult> CreateOrUpdate(OrderModel model, int updateBy = 0, string updateByUserName = "")
        {
            var ward = _wardService.Get(model.WardId);

            model.Address = ward.Name + ward.District.Name + ward.District.City.Name;
            List <OrderItemModel> order_Items = null;

            if (model.ListOrderItem != null)
            {
                order_Items         = model.ListOrderItem;
                model.ListOrderItem = null;
            }
            var order = model.ToOrder();

            if (order.Id > 0)
            {
                if (order_Items != null)
                {
                    List <int> listInDTB         = _orderItemService.GetOrderItemByOrderId(model.Id).ToList();
                    List <int> orderItemUpdateID = new List <int> {
                    };
                    foreach (OrderItemModel orderItemModel2 in order_Items)
                    {
                        await _orderItemService.CreateOrUpdate(orderItemModel2);

                        orderItemUpdateID.Add(orderItemModel2.Id);
                    }

                    foreach (int a in listInDTB)
                    {
                        if (!orderItemUpdateID.Contains(a))
                        {
                            await _orderItemService.Delete(a);
                        }
                    }

                    order_Items = null;
                }
                //Cập nhật
                return(await Update(order));
            }
            else
            {
                order.CreatedTime = DateTime.Now;
                CreateOrUpdateResultInt rs = await Create(order);

                if (order_Items != null)

                {
                    foreach (OrderItemModel orderItemModel2 in order_Items)
                    {
                        orderItemModel2.OrderId = rs.Id;

                        await _orderItemService.CreateOrUpdate(orderItemModel2);
                    }
                }


                return(rs);
            }
        }
예제 #4
0
 public WardModel Get(int id)
 {
     return(_wardService.Get(id));
 }
예제 #5
0
        public async Task <IActionResult> Shipping(CartViewModel cartViewModel)
        {
            List <Province>          provinces;                                           // List of Province
            List <District>          districts;                                           // List of District
            List <Ward>              wards;                                               // List of Ward
            ProvinceViewModel        provinceViewModel;                                   // Province view model
            List <ProvinceViewModel> provinceViewModels = new List <ProvinceViewModel>(); // List of Province view model
            DistrictViewModel        districtViewModel;                                   // District view model
            List <DistrictViewModel> districtViewModels = new List <DistrictViewModel>(); // List of District view model
            WardViewModel            wardViewModel;                                       // Ward view model
            List <WardViewModel>     wardViewModels = new List <WardViewModel>();         // List of Ward view model
            Order          order;                                                         // List of Order
            OrderViewModel orderViewModel;                                                // Order view model

            // Get current User
            var user = await userManager.GetUserAsync(User);

            if (user == null)
            {
                return(RedirectToAction("SignIn", "Login"));
            }

            // Get all Provinces and mapping to view model
            provinces = provinceService.GetAll();
            foreach (var item in provinces)
            {
                provinceViewModel = new ProvinceViewModel(item);
                provinceViewModels.Add(provinceViewModel);
            }

            var hcmProvince = provinces.Where(p => p.Id == 79).First();

            // Get first District and mapping to view model
            districts = districtService.Get(hcmProvince.Id);
            foreach (var item in districts)
            {
                districtViewModel = new DistrictViewModel(item);
                districtViewModels.Add(districtViewModel);
            }

            // Get first Ward and mapping to view model
            wards = wardService.Get(districts.First().Id);
            foreach (var item in wards)
            {
                wardViewModel = new WardViewModel(item);
                wardViewModels.Add(wardViewModel);
            }

            // Remove products which out of stock
            cartViewModel.Cart = cartViewModel.Cart.Where(cd => cd.BuyedQuantity != 0).ToList();

            // Mapping to view model
            ShippingViewModel model = new ShippingViewModel()
            {
                Id            = user.Id,
                Name          = user.HoTen,
                PhoneNumber   = user.PhoneNumber,
                Provinces     = provinceViewModels,
                Districts     = districtViewModels,
                Wards         = wardViewModels,
                CartViewModel = cartViewModel
            };

            // Get old order's info of current user
            order = orderService.GetOrderOfUser(user.Id);
            if (order != null)
            {
                orderViewModel = new OrderViewModel(order);
                model.Order    = orderViewModel;
            }

            return(View("Shipping", model));
        }