public int AddOrder(string title) { //begin mapping values to order business component OrderEntity order = new OrderEntity(); order.Title = title; //end mapping values to order business component return(orderBusiness.Add(order)); }
public virtual JsonResult AddOrder(AddOrderModel model, List <HttpPostedFileBase> attachments) { if (!ModelState.IsValid) { return(Json(new ActionResponse <string> { Message = LocalMessage.ValidationFailed })); } var addUser = _userSrv.Insert(model); if (!addUser.IsSuccessful) { return(Json(addUser)); } model.UserId = addUser.Result; var userInRole = new UserInRole { UserId = addUser.Result, RoleId = int.Parse(AppSettings.EndUserRoleId), IsActive = true, ExpireDateSh = PersianDateTime.Now.AddYears(5).ToString(PersianDateTimeFormat.Date) }; if (!_userInRoleBusiness.Value.CheckExist(userInRole)) { _userInRoleBusiness.Value.Insert(userInRole); } model.Status = OrderStatus.WaitForPricing; model.DayToDeliver = byte.Parse(AppSettings.DefaultDayToDeliver); var addOrder = _orderSrv.Add(model); if (!addOrder.IsSuccessful) { return(Json(addUser)); } var addFiles = _attachmentSrv.Insert(addOrder.Result, AttachmentType.OrderFiles, attachments); addOrder.Result.User = new User { FirstName = model.FirstName, LastName = model.LastName, Email = model.Email, MobileNumber = long.Parse(model.MobileNumber) }; return(Json(new { addFiles.IsSuccessful, addFiles.Message, Result = MvcExtention.RenderViewToString(this, MVC.Home.Views.Partials._AfterAdd, addOrder.Result) })); }
public ActionResult Payment(PaymentParam model) { try { HttpCookie reqCookies = Request.Cookies["MemberLoginCookie"]; ResponseMemberLogin login = JsonConvert.DeserializeObject <ResponseMemberLogin>(reqCookies.Value.ToString().UrlDecode()); if (login == null || login.ID == 0) { return(Json(new PaymentResult { Status = -1, Uri = "" })); } double reduce = 0; var tour = _tourBusiness.GetDetail(model.TourID); if (tour != null && tour.ID != 0) { var steps = _stepBusiness.GetAll(tour.ID); if (model.PCode != "") { var promotion = _promotionBusiness.ApplyPromotion(model.PCode); if (promotion != null && promotion.ID != 0) { if (promotion.TourApply == "" || promotion.TourApply == null) { if (promotion.Type == 1) { reduce = promotion.AmountReduced; } else { reduce = (tour.Price * promotion.PercentReduced) / 100; } } else { if (promotion.TourApply.Contains(tour.ID.ToString())) { if (promotion.Type == 1) { reduce = promotion.AmountReduced; } else { reduce = (tour.Price * promotion.PercentReduced) / 100; } } } } } OrderView order = new OrderView(); order.Amount = tour.Price - reduce; order.Code = $"{DateTime.Now.ToString("ddMMyy")}{RandomUtils.RandomString(6, 8, true, true, false)}"; order.Date = DateTime.Now; order.IsPayment = false; order.Member = login.ID; order.MemberName = login.Name; order.Price = tour.Price; order.Reduce = reduce; order.Status = 0; order.Step = 0; order.Tour = tour.ID; if (_orderBusiness.Add(order)) { _orderBusiness.Save(); long oID = _orderBusiness.GetID(order.Code); if (steps != null && steps.Count() > 0 && oID != 0) { int max = steps.Count(); int count = 1; foreach (var item in steps) { OrderDetailView detail = new OrderDetailView(); detail.IsAccomplish = false; if (count == max) { detail.IsLastStep = true; } else { detail.IsLastStep = false; } detail.OrderID = oID; detail.Rank = count; detail.StepID = item.ID; detail.StepName = item.Name; if (_orderDetailBusiness.Add(detail)) { _orderDetailBusiness.Save(); } count++; } } if (model.TypePay == 0) { string uri = CreateRequestPaymentPort(order.Amount.ToString(), order.Code, login.ID.ToString()); return(Json(new PaymentResult { Status = 1, Uri = uri })); } if (model.TypePay == 1) { string uri = CreateRequestPaymentPortGlobal(order.Amount.ToString(), order.Code, login.ID.ToString()); return(Json(new PaymentResult { Status = 1, Uri = uri })); } } } return(Json(new PaymentResult { Status = -1, Uri = "" })); } catch (Exception) { return(Json(new PaymentResult { Status = -1, Uri = "" })); } }
public ActionResult Payment(PaymentParam model) { try { if (model != null) { if (Request.Cookies["MemberLoginCookie"] == null) { return(Json(new PaymentResult { Status = -1, Uri = "" })); } HttpCookie reqCookies = Request.Cookies["MemberLoginCookie"]; ResponseMemberLogin login = JsonConvert.DeserializeObject <ResponseMemberLogin>(reqCookies.Value.ToString().UrlDecode()); if (login == null || login.ID == 0) { return(Json(new PaymentResult { Status = -1, Uri = "" })); } if (Session["ListShoppingCart"] == null) { return(Json(new PaymentResult { Status = -1, Uri = "" })); } List <Cart> carts = (List <Cart>)Session["ListShoppingCart"]; if (carts == null || carts.Count() <= 0) { return(Json(new PaymentResult { Status = -1, Uri = "" })); } List <string> codes = new List <string>(); List <string> id = new List <string>(); double amount = 0; string Code = ""; Code += RandomUtils.RandomString(7, 9, true, true, false); if (_orderBusiness.CheckExistsCode(Code)) { Code = RandomUtils.RandomString(7, 9, true, true, false); } Code = Code.ToUpperCase(true); OrderView order = new OrderView(); order.Amount = carts.Sum(x => x.Total); order.Code = Code; order.Date = DateTime.Now; order.Member = login.ID; order.Receipt = model.ReceiptID; //order.Reduce=carts.Sum(x=>x.re) order.StatusOrder = 0; order.StatusPayment = 0; order.Total = carts.Sum(x => x.Total); order.TypePayment = model.TypePay; if (_orderBusiness.Add(order)) { _orderBusiness.Save(); foreach (var d in carts) { OrderDetailView detail = new OrderDetailView(); detail.Code = Code; detail.Price = d.Price; detail.Product = d.ID; detail.Qty = d.Qty; detail.Reduce = 0; detail.Total = d.Total; if (_orderDetailBusiness.Add(detail)) { _orderDetailBusiness.Save(); } } } amount = order.Amount; Session["ListShoppingCart"] = null; if (model.TypePay == 2) { return(Json(new PaymentResult { Status = 1, Uri = $"/xac-nhan-dat-hang.html?code={Code}" })); } if (model.TypePay == 0) { string uri = CreateRequestPaymentPort((amount * 100).ToString(), Code, login.Name); return(Json(new PaymentResult { Status = 1, Uri = uri })); } if (model.TypePay == 1) { string uri = CreateRequestPaymentPortGlobal((amount * 100).ToString(), Code, login.Name); return(Json(new PaymentResult { Status = 1, Uri = uri })); } } return(Json(new PaymentResult { Status = -1, Uri = "" })); } catch (Exception) { return(Json(new PaymentResult { Status = -1, Uri = "" })); } }