public void CreateOrder(OrderInput input) { if (input.Details == null || !input.Details.Any()) { throw new KnownException("订单错误找不到详情"); } var header = _mapper.Map <OrderHeader>(input); var details = _mapper.Map <List <Data.OrderDetail> >(input.Details); details.ForEach(x => x.ParentId = header.Id); header.Amount = details.Sum(x => x.Price * x.Quantity); var msg = _mapper.Map <OrderCreatedEvent>(header); msg.Details = _mapper.Map <List <Message.OrderDetail> >(details); var dbMessage = new MqMessage() { Body = JsonConvert.SerializeObject(msg, new JsonSerializerSettings() { ContractResolver = new CamelCasePropertyNamesContractResolver(), DateFormatString = "yyyy-MM-dd hh:mm:ss" }), MessageAssemblyName = typeof(OrderCreatedEvent).Assembly.GetName().Name, MessageClassFullName = msg.GetType().FullName }; _dbContext.Add(dbMessage); _dbContext.Add(header); _dbContext.AddRange(details); _dbContext.SaveChanges(); }
public void AddNewDepartment(Department newDepartment) { Department newDepart = (Department)newDepartment; _context.Add(newDepart); _context.SaveChanges(); }
/// <summary> /// Creates a new product. /// </summary> /// <param name="product"></param> /// <returns>Newly created project</returns> public async Task <Product> CreateProduct(Product product) { _context.Add(product); await _context.SaveChangesAsync(); return(product); }
public async Task <Product> AddProduct(Product product) { var p = _dbContext.Add(product); _dbContext.SaveChanges(); return(product); //throw new System.NotImplementedException(); }
public void addProduct(Product product) { using (var db = new ProductDbContext()) { db.Add(product); db.SaveChanges(); } }
public SaveForLater SaveForLater(int ProductId, string userId) { SaveForLater newProduct = new SaveForLater(); newProduct.ProductId = ProductId; newProduct.UserId = userId; _context.Add(newProduct); _context.SaveChanges(); return(newProduct); }
public async Task <IActionResult> Create([Bind("Name,Surname,Address,Zipcode,Id,UserName,NormalizedUserName,Email,NormalizedEmail,EmailConfirmed,PasswordHash,SecurityStamp,ConcurrencyStamp,PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEnd,LockoutEnabled,AccessFailedCount")] ApplicationUser applicationUser) { if (ModelState.IsValid) { _context.Add(applicationUser); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(applicationUser)); }
public async Task <IActionResult> Create([Bind("Id,Name,Code")] Color color) { if (ModelState.IsValid) { _context.Add(color); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(color)); }
public async Task <IActionResult> Create([Bind("Id,Style,Color,Sku,Title,Price,Stock")] Product.Entities.Product product) { if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(product)); }
public async Task <IActionResult> Create([Bind("Id,Type,Name,Description,Price,Amount")] Product product) { if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(product)); }
public async Task <IActionResult> Create([Bind("ID,Title,Description,PhoneNumber,Address,Email")] About about) { if (ModelState.IsValid) { _context.Add(about); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(about)); }
public async Task <bool> CreateAsync(ProductEntity product) { if (!IsIDExistsAsync(product.ProductID).Result) { _context.Add(product); await _context.SaveChangesAsync(); return(true); } return(false); }
public async Task <IActionResult> Create([Bind("ID,Name")] Menu menu) { if (ModelState.IsValid) { _context.Add(menu); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(menu)); }
public async Task <IActionResult> Create([Bind("PId,PName,PDesc,PPrice")] Product product) { if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(product)); }
public async Task <IActionResult> Create([Bind("Id,Name,SubMenuID")] Category category) { if (ModelState.IsValid) { _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["SubMenuID"] = new SelectList(_context.SubMenus, "Id", "Name", category.SubMenuID); return(View(category)); }
public async Task <IActionResult> Create([Bind("id,name,value,productid")] Specification specification) { if (ModelState.IsValid) { _context.Add(specification); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["productid"] = new SelectList(_context.Products, "id", "id", specification.ProductId); return(View(specification)); }
public async Task <IActionResult> Create([Bind("Id,Name,MarkaID")] Model model) { if (ModelState.IsValid) { _context.Add(model); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["MarkaID"] = new SelectList(_context.Markas, "Id", "Name", model.MarkaID); return(View(model)); }
public async Task <IActionResult> Create([Bind("Id,Name,MenuId")] SubMenu subMenu) { if (ModelState.IsValid) { _context.Add(subMenu); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["MenuId"] = new SelectList(_context.Menus, "ID", "Name", subMenu.MenuId); return(View(subMenu)); }
public async Task <IActionResult> Create([Bind("Id,Name,CategoryId")] Marka marka) { if (ModelState.IsValid) { _context.Add(marka); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewBag.Menu = new SelectList(_context.Menus, "ID", "Name"); return(View(marka)); }
public int Add(Models.Product item) { try { var NewItem = dbContext.Add(item); Save(); return(NewItem.Entity.ProductId); } catch (Exception) { return(0); } }
public bool Add(Product model) { try { _productDbContext.Add(model); _productDbContext.SaveChanges(); } catch (System.Exception) { return(false); } return(true); }
public async Task <bool> AddProduct(ProductDto product) { try { var productModel = _mapper.Map <ProductModel>(product); _db.Add(productModel); _db.SaveChanges(); flag = true; return(await Task.FromResult(flag)); } catch { flag = false; return(await Task.FromResult(flag)); } }
public IActionResult createCategory(Category category) { if (!ValidId(category.CategoryId)) { return(StatusCode(400, "Id must be less than 6")); } dbContext.Add(category); try { dbContext.SaveChanges(); } catch { if (CategoryExists(category.CategoryId)) { return(StatusCode(400, "Category is existed")); } else { throw; } } return(Ok(category)); }
public void SaveOrder(ShoppingOrder ShoppingOrder) { ShoppingOrder.Create_Date = DateTime.Now; _context.Add(ShoppingOrder); _context.SaveChanges(); }
public void AddNewProduct(Product newProduct) { _context.Add(newProduct); _context.SaveChanges(); }
public void AddProduct(Product product) { _dbContext.Add(product); _dbContext.SaveChanges(); }
public async Task Create(Product product) { _context.Add(product); await _context.SaveChangesAsync(); }
public async Task <int> SaveAsync(ProductViewModel product) { _context.Add(product); return(await _context.SaveChangesAsync()); }