public ActionResult Create([Bind] OrderViewModel order, string ReturnUrl) { ActionResult action; try { if (!base.ModelState.IsValid) { base.ModelState.AddModelError("", MessageUI.ErrorMessage); return(base.View(order)); } else { HttpFileCollectionBase files = base.Request.Files; List <OrderGallery> orderGalleries = new List <OrderGallery>(); if (files.Count > 0) { int count = files.Count - 1; int num = 0; string[] allKeys = files.AllKeys; for (int i = 0; i < (int)allKeys.Length; i++) { string str = allKeys[i]; if (num <= count) { if (!str.Equals("Image")) { HttpPostedFileBase httpPostedFileBase = files[num]; if (httpPostedFileBase.ContentLength > 0) { OrderGalleryViewModel orderGalleryViewModel = new OrderGalleryViewModel() { OrderId = order.Id }; string str1 = string.Format("{0}-{1}.jpg", order.OrderCode, Guid.NewGuid()); this._imagePlugin.CropAndResizeImage(httpPostedFileBase, string.Format("{0}{1}/", Contains.ImageFolder, order.OrderCode), str1, new int?(ImageSize.WithBigSize), new int?(ImageSize.WithBigSize), false); orderGalleryViewModel.ImagePath = string.Format("{0}{1}/{2}", Contains.ImageFolder, order.OrderCode, str1); orderGalleries.Add(Mapper.Map <OrderGallery>(orderGalleryViewModel)); } num++; } else { num++; } } } } Order order1 = Mapper.Map <OrderViewModel, Order>(order); if (orderGalleries.IsAny <OrderGallery>()) { order1.OrderGalleries = orderGalleries; } List <OrderItem> orderItems = new List <OrderItem>(); if (order.OrderItems.IsAny <OrderItemViewModel>()) { orderItems.AddRange( from item in order.OrderItems select Mapper.Map <OrderItem>(item)); } if (orderItems.IsAny <OrderItem>()) { order1.OrderItems = orderItems; } this._orderService.Create(order1); base.Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.CreateSuccess, FormUI.Order))); if (!base.Url.IsLocalUrl(ReturnUrl) || ReturnUrl.Length <= 1 || !ReturnUrl.StartsWith("/") || ReturnUrl.StartsWith("//") || ReturnUrl.StartsWith("/\\")) { action = base.RedirectToAction("Index"); } else { action = this.Redirect(ReturnUrl); } } } catch (Exception exception1) { Exception exception = exception1; ExtentionUtils.Log(string.Concat("Order.Create: ", exception.Message)); base.ModelState.AddModelError("", exception.Message); return(base.View(order)); } return(action); }
public ActionResult BuyProduct(OrderViewModel order) { int id = 1; Order order1 = this._orderService.GetTop <int>(1, (Order x) => x.Id > 0, (Order x) => x.Id).FirstOrDefault <Order>(); if (order1 != null) { id = order1.Id; } order.OrderCode = string.Concat("DH", id.ToString()); order.CustomerCode = string.Concat("KH", id.ToString()); order.Category = "Định giá và thu mua sản phẩm"; if (!base.Request.IsAjaxRequest()) { return(base.Json(new { success = false, errors = string.Join(", ", base.ModelState.Values.SelectMany <System.Web.Mvc.ModelState, string>((System.Web.Mvc.ModelState v) => from x in v.Errors select x.ErrorMessage).ToArray <string>()) })); } HttpFileCollectionBase files = base.Request.Files; List <OrderGallery> orderGalleries = new List <OrderGallery>(); if (files.Count > 0) { int count = files.Count - 1; int num = 0; string[] allKeys = files.AllKeys; for (int i = 0; i < (int)allKeys.Length; i++) { string str = allKeys[i]; if (num <= count) { if (!str.Equals("Image")) { HttpPostedFileBase item = files[num]; if (item.ContentLength > 0) { OrderGalleryViewModel orderGalleryViewModel = new OrderGalleryViewModel() { OrderId = order.Id }; string str1 = string.Format("{0}-{1}.jpg", order.OrderCode, Guid.NewGuid()); this._imagePlugin.CropAndResizeImage(item, string.Format("{0}{1}/", Contains.ImageFolder, order.OrderCode), str1, new int?(ImageSize.WithBigSize), new int?(ImageSize.WithBigSize), false); orderGalleryViewModel.ImagePath = string.Format("{0}{1}/{2}", Contains.ImageFolder, order.OrderCode, str1); orderGalleries.Add(Mapper.Map <OrderGallery>(orderGalleryViewModel)); } num++; } else { num++; } } } } Order order2 = Mapper.Map <OrderViewModel, Order>(order); if (orderGalleries.IsAny <OrderGallery>()) { order2.OrderGalleries = orderGalleries; } this._orderService.Create(order2); return(base.Json(new { success = true })); }
public ActionResult Edit([Bind] OrderViewModel orderView, string ReturnUrl) { ActionResult action; try { if (!base.ModelState.IsValid) { base.ModelState.AddModelError("", MessageUI.ErrorMessage); return(base.View(orderView)); } else { Order order = this._orderService.Get((Order x) => x.Id == orderView.Id, false); HttpFileCollectionBase files = base.Request.Files; List <OrderGallery> orderGalleries = new List <OrderGallery>(); if (files.Count > 0) { int count = files.Count - 1; int num = 0; string[] allKeys = files.AllKeys; for (int i = 0; i < (int)allKeys.Length; i++) { string str = allKeys[i]; if (num <= count) { if (!str.Equals("Image")) { HttpPostedFileBase item = files[num]; if (item.ContentLength > 0) { OrderGalleryViewModel orderGalleryViewModel = new OrderGalleryViewModel() { OrderId = orderView.Id }; string str1 = string.Format("{0}-{1}.jpg", orderView.OrderCode, Guid.NewGuid()); this._imagePlugin.CropAndResizeImage(item, string.Format("{0}{1}/", Contains.ImageFolder, orderView.OrderCode), str1, new int?(ImageSize.WithBigSize), new int?(ImageSize.WithBigSize), false); orderGalleryViewModel.ImagePath = string.Format("{0}{1}/{2}", Contains.ImageFolder, orderView.OrderCode, str1); orderGalleries.Add(Mapper.Map <OrderGallery>(orderGalleryViewModel)); } num++; } else { num++; } } } } if (orderGalleries.IsAny <OrderGallery>()) { order.OrderGalleries = orderGalleries; } List <OrderItem> orderItems = new List <OrderItem>(); if (orderView.OrderItems.IsAny <OrderItemViewModel>()) { foreach (OrderItemViewModel orderItem in orderView.OrderItems) { OrderItemViewModel orderItemViewModel = new OrderItemViewModel(); if (orderItem.Id > 0) { orderItemViewModel.Id = orderItem.Id; } orderItemViewModel.OrderId = orderView.Id; orderItemViewModel.FixedFee = orderItem.FixedFee; orderItemViewModel.Category = orderItem.Category; orderItemViewModel.WarrantyFrom = orderItem.WarrantyFrom; orderItemViewModel.WarrantyTo = orderItem.WarrantyTo; orderItems.Add(Mapper.Map <OrderItem>(orderItemViewModel)); } } if (orderItems.IsAny <OrderItem>()) { order.OrderItems = orderItems; } IEnumerable <OrderItem> orderItems1 = this._orderItemService.FindBy((OrderItem x) => x.OrderId == orderView.Id, false); this._orderItemService.BatchDelete(orderItems1); order = Mapper.Map <OrderViewModel, Order>(orderView, order); this._orderService.Update(order); base.Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.UpdateSuccess, FormUI.Order))); if (!base.Url.IsLocalUrl(ReturnUrl) || ReturnUrl.Length <= 1 || !ReturnUrl.StartsWith("/") || ReturnUrl.StartsWith("//") || ReturnUrl.StartsWith("/\\")) { action = base.RedirectToAction("Index"); } else { action = this.Redirect(ReturnUrl); } } } catch (Exception exception1) { Exception exception = exception1; base.ModelState.AddModelError("", exception.Message); ExtentionUtils.Log(string.Concat("Order.Edit: ", exception.Message)); return(base.View(orderView)); } return(action); }