public ActionResult Create(SaleViewModel model) { try { foreach (var item in Request.Form["products.index"].Split(',')) { var spvm = new SaleProductViewModel() { ProductId = Convert.ToInt32(item), Quantity = Convert.ToInt32(Request.Form["products[" + item + "].quantity"]), UnitPrice = Convert.ToDecimal(Request.Form["products[" + item + "].unitValue"], CultureInfo.InvariantCulture) }; model.SaleProducts.Add(spvm); } if (!ModelState.IsValid) { ViewBag.CustomerId = new SelectList(_customerService.GetAll(), "Id", "Name", model.CustomerId); return(View(model)); } _service.Create(_mapper.Map <Sale>(model)); return(RedirectToAction("Index")); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(View(model)); } }
public virtual async void TestDelete() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); client.SetBearerToken(JWTTestHelper.GenerateBearerToken()); ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext; ISaleService service = testServer.Host.Services.GetService(typeof(ISaleService)) as ISaleService; var model = new ApiSaleServerRequestModel(); model.SetProperties(2m, 2, "B", 1, DateTime.Parse("1/1/1988 12:00:00 AM"), 2); CreateResponse <ApiSaleServerResponseModel> createdResponse = await service.Create(model); createdResponse.Success.Should().BeTrue(); ActionResponse deleteResult = await client.SaleDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiSaleServerResponseModel verifyResponse = await service.Get(2); verifyResponse.Should().BeNull(); }
public async Task <ActionResult <SaleHeaderDto> > PostSale(PostSaleHeaderDto postSaleHeaderDto) { SaleHeader result = _mapper.Map <SaleHeader>(postSaleHeaderDto); _saleService.Create(result); return(CreatedAtAction(nameof(GetSale), new { id = result.Id }, _mapper.Map <SaleHeaderDto>(result))); }
public IActionResult RealizationPost([FromBody] RealizationVM json) { try { var managerId = _postgresContext.Managers.FirstOrDefault(x => x.Name == json.Manager)?.Id ?? throw new Exception("Не указан менеджен"); SaleCreateVM saleCreate = new SaleCreateVM() { UserId = json.UserId, MoneyWorkerId = json.MoneyWorkerId, Discount = json.Discount, AdditionalComment = json.AdditionalComment, Comment = json.Comment, PaymentType = json.Cashless ? PaymentType.Cashless : PaymentType.Cash, CashSum = json.CashSum, CashlessSum = json.CashlessSum, Sum = json.Sum, Products = json.Products, PartnerId = json.Buyer == "Обычный покупатель" ? null : _db.Partners.First(p => p.Title == json.Buyer)?.Id, Payment = json.Payment, ForRussian = json.ForRussian }; var createdSale = _saleService.Create(_db, saleCreate, json.UserId); _postgresContext.SaleManagersOld.Add( new SaleManagerOld(managerId, createdSale.Id, DateTime.Now.AddHours(3))); _postgresContext.SaveChanges(); return(RedirectToAction("CheckPrint", new { saleId = createdSale.Id, operationSum = json.CashSum + json.CashlessSum })); } catch (Exception e) { return(BadRequest(new { message = e.Message })); } }
public async Task <IActionResult> Create([FromBody] Sale sale) { var result = await _service.Create(sale); return(result.ToString() switch { "{ Message = Produto não encontrado. }" => NotFound(result), "{ Message = Quantidade indisponível no estoque. }" => BadRequest(result), _ => Ok(result) });
public IActionResult Create(SaleDto saleDto) { try { _saleService.Create(saleDto); return(Ok()); } catch (CustomException exception) { return(StatusCode(exception.ErrorDetails.StatusCode, exception.ErrorDetails)); } }
public async Task <IActionResult> Create([FromBody] Sale sale) { var saleId = await saleService.Create(sale); var paymentUrl = $"https://safraapi.azurewebsites.net/payment/{saleId}"; //var paymentUrl = $"http://localhost:54671/api/v1/payment/{saleId}"; if (saleId != null) { return(Created( "Sale", new { Url = paymentUrl })); } else { return(BadRequest()); } }
public void Post([FromBody] Sale sale) { _saleService.Create(sale); }
public virtual ActionResult Payment(StatusTypePay selectPayment = StatusTypePay.Online) { var list = new List <BasketViewModel>(); if (Request.Browser.Cookies) { if (Request.Cookies["Basket"] != null) { HttpCookie cookie = Request.Cookies["Basket"]; string valueCookie = cookie["Cart"]; var resultDecrypt = new EnDecryption().Decryption(valueCookie); list = SerializeList.DeseraLizeList(resultDecrypt); var sale = new Sale { Date = DateTime.Now, Postage = 8000, Price = list.Sum(x => x.Price), StatusTypePay = selectPayment.ToString(), StatusUltimate = false, StatusSend = false, User_Id = User.Identity.GetUserId <int>(), }; var orderList = new List <Order>(); list.ForEach(x => { orderList.Add(new Order { Name = x.Name, Price = x.Price, Quantity = x.Quantity, StatusTypeOrder = StatusTypeOrder.EWPR.ToString(), Product_Id = x.Product_Id }); }); sale.Orders = orderList; _saleService.Create(sale); if (_unitOfWork.SaveAllChanges() > 0) { HttpCookie cookieCode = new HttpCookie("TrackingNumber"); cookieCode.Values["Code"] = new EnDecryption().Encryption(((sale.Id * 347) + 2323).ToString()); cookieCode.Expires = DateTime.Now.AddMinutes(10); Response.Cookies.Add(cookieCode); if (selectPayment == StatusTypePay.Online) { return(Json(new { Status = "true", Result = "ثبت سفارش با موفقیت صورت گرفت", Address = "Ultimate/" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { Status = "true", Result = "ثبت سفارش با موفقیت صورت گرفت", Address = "Ultimate/" }, JsonRequestBehavior.AllowGet)); } } else { return(Json(new { Status = "false", Result = "متاسفانه در ثبت سفارش خطایی رخ داده شده است مجدد صفحه را بروز رسانی کنید" }, JsonRequestBehavior.AllowGet)); } } else { return(RedirectToAction(MVC.Home.ActionNames.Index, MVC.Home.Name)); } } else { return(RedirectToAction(MVC.Home.ActionNames.Index, MVC.Home.Name)); } }
public ActionResult CompleteShopping() { try { var userId = this.HttpContext.Session.GetString("UserId"); var baskets = _basketService.GetAll().Where(x => x.UserCode == userId).ToList(); #region Ödeme Modeline Bilgiler Set Ediliyor. SalesDTO sales = new SalesDTO() { Status = Status.Active, UploadDate = DateTime.Now, UpdateDate = DateTime.Now, }; #endregion baskets.ForEach(x => { #region Ürün Stok Bilgisi Güncelleniyor. var product = _productService.GetAll().Where(c => c.ProductId == x.ProductCode).FirstOrDefault(); if (product != null) { product.Stock -= x.Quantity; var res = _productService.Update(product); } #endregion #region Sepetdeki Ürün Satış İşleminden Dolayı Statusu Silindiye Çekiliyor. x.Status = Status.Deleted; _basketService.Update(x); #endregion #region Ödeme Modeline Bilgiler Set Ediliyor. sales.TotalPrice += x.Price * x.Quantity; sales.PaymentType = "Kredi Kartı (Tek Çekim)"; sales.TotalQuantity += x.Quantity; sales.UserCode = userId; var userDto = _userService.Get(Convert.ToInt32(userId)); if (userDto.IsSuccess) { sales.UserName = userDto.Result.UserName; } #endregion }); var result = _saleService.Create(sales); if (result.Result != null && result.IsSuccess) { #region Sepet Session'ı Güncelleniyor. List <BasketDTO> basketsSession = _basketService.GetAll().Where(x => x.Status == Status.Active && x.UserCode == this.HttpContext.Session.GetString("UserId")).ToList(); HttpContext.Session.Set <List <BasketDTO> >("BasketCard", basketsSession); return(Json(true)); #endregion } else { return(Json(false)); } } catch (Exception) { return(Json(false)); } }