public async Task <IActionResult> Create([Bind("OrderId,ProductId,UnitPrice,Quantity,Discount")] OrderDetails orderDetails, string submitButton) { if (ModelState.IsValid) { switch (submitButton) { case "Create Order": { _context.Add(orderDetails); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }; case "Add more products to order": { _context.Add(orderDetails); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Create), new { id = orderDetails.OrderId })); }; } } ViewData["OrderId"] = new SelectList(_context.Orders, "OrderId", "OrderId", orderDetails.OrderId); ViewData["ProductId"] = new SelectList(_context.Products, "ProductId", "ProductName", orderDetails.ProductId); return(View(orderDetails)); }
public async Task <CartLineDto> AddCartLine(string customerId, CartLineForCreationDto cartLine, CancellationToken cancellationToken = default(CancellationToken)) { if (string.IsNullOrEmpty(customerId)) { throw new ArgumentNullException(nameof(customerId)); } var userCart = await GetUserCartEntity(customerId, cancellationToken); if (userCart == null) { userCart = new Cart { CustomerId = customerId }; _context.Add(userCart); } var result = userCart.AddCartLine(cartLine.Map(CartMapper.CartLineForCreationDtoToEntityFunc)); await _context.SaveChangesAsync(cancellationToken); var cartLineDto = result.Map(CartMapper.CartLineEntityToDto); if (cartLineDto != null && string.IsNullOrEmpty(cartLineDto.ProductName)) { cartLineDto.ProductName = cartLine.ProductName; } return(cartLineDto); }
public async Task <Product> CreateProduct(Product product) { _context.Add(product); await _context.SaveChangesAsync(); return(product); }
public string Post([FromBody] CourseDTO courseDTO) { ValidatorResult validatorResult = CourseValidator.IsValidCourse(courseDTO); if (!validatorResult.IsValid) { HttpContext.Response.StatusCode = 422; return(JsonConvert.SerializeObject(validatorResult.ValidationMessage)); } Course course = new Course() { Name = courseDTO.Name, Description = courseDTO.Description, Length = courseDTO.Length, StartDate = courseDTO.StartDate, EndDate = courseDTO.EndDate }; //Add to DB try { northwindContext.Add(course); northwindContext.SaveChanges(); HttpContext.Response.StatusCode = 200; return(JsonConvert.SerializeObject("The course is successfully saved.")); } catch (Exception e) { HttpContext.Response.StatusCode = 520; return(JsonConvert.SerializeObject(e.Message)); } }
public Product Create(Product newProduct) { using var Context = new NorthwindContext(); Context.Add(newProduct); Context.SaveChanges(); return(newProduct); }
public async Task <Category> CreateCategoryAsync(Category category) { _context.Add(category); await _context.SaveChangesAsync(); return(category); }
public async Task <IActionResult> Create(Products products, IFormFile Image) { if (ModelState.IsValid) { if (Image != null) { if (Image.Length > 0) //Convert Image to byte and save to database { byte[] p1 = null; using (var fs1 = Image.OpenReadStream()) using (var ms1 = new MemoryStream()) { fs1.CopyTo(ms1); p1 = ms1.ToArray(); } products.Photo = p1; } } _context.Add(products); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CategoryId"] = new SelectList(_context.Categories, "CategoryId", "CategoryName", products.CategoryId); ViewData["SupplierId"] = new SelectList(_context.Suppliers, "SupplierId", "CompanyName", products.SupplierId); return(View(products)); }
static void Main(string[] args) { var db = new NorthwindContext(); db.Add(new Osoba() {Name="Michal",DateTime=DateTime.Now, RegistrationDate=DateTime.Now}); db.SaveChanges(); }
public void create(Customer entity, NorthwindContext context) { string id = createId(); entity.CustomerId = id; context.Add(entity); context.SaveChanges(); }
/*public void AddOrderDetail(Products product, Orders order) * { * using(NorthwindContext context = new NorthwindContext()) * { * context.Add() * } * }*/ /// <summary> /// Adds an object of any type to the database /// </summary> /// <param name="objectToAdd">Object to add to the database</param> static public void AddToDatabase(Object objectToAdd) { using (NorthwindContext context = new NorthwindContext()) { context.Add(objectToAdd); context.SaveChanges(); } }
internal void create(CustomerDemographic entity, NorthwindContext context) { string id = createId(); entity.CustomerTypeId = id; context.Add(entity); context.SaveChangesAsync(); }
public void AddCategory(Categories categoryToAdd) { if (categoryToAdd == null) { throw new ArgumentNullException(nameof(categoryToAdd)); } _context.Add(categoryToAdd); }
public async Task <IActionResult> Create([Bind("OrderId,CustomerId,EmployeeId,OrderDate,RequiredDate,ShippedDate,ShipVia,Freight,ShipName,ShipAddress,ShipCity,ShipRegion,ShipPostalCode,ShipCountry,OrderDetails,ProductId,UnitPrice,Quantity,Discount")] OrderViewModel order) { if (ModelState.IsValid) { Orders o = new Orders { OrderId = order.OrderId, CustomerId = order.CustomerId, EmployeeId = order.EmployeeId, OrderDate = order.OrderDate, RequiredDate = order.RequiredDate, ShippedDate = order.ShippedDate, ShipVia = order.ShipVia, Freight = order.Freight, ShipName = order.ShipName, ShipAddress = order.ShipAddress, ShipCity = order.ShipCity, ShipRegion = order.ShipRegion, ShipPostalCode = order.ShipPostalCode, ShipCountry = order.ShipCountry }; OrderDetails d = new OrderDetails { OrderId = order.OrderId, Order = o, ProductId = order.ProductId, UnitPrice = order.UnitPrice, Quantity = order.Quantity, Discount = order.Discount }; _context.Add(o); _context.Add(d); await _context.SaveChangesAsync(); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ProductId"] = new SelectList(_context.Products, "ProductId", "ProductName"); ViewData["CustomerId"] = new SelectList(_context.Customers, "CustomerId", "CustomerId", order.CustomerId); ViewData["EmployeeId"] = new SelectList(_context.Employees, "EmployeeId", "FirstName", order.EmployeeId); ViewData["ShipVia"] = new SelectList(_context.Shippers, "ShipperId", "CompanyName", order.ShipVia); return(View(order)); }
public async Task<IActionResult> Create([Bind("EmployeeId,LastName,FirstName,Title,TitleOfCourtesy,BirthDate,HireDate,Address,City,Region,PostalCode,Country,HomePhone,Extension,Photo,Notes,ReportsTo,PhotoPath")] Employees employees) { if (ModelState.IsValid) { _context.Add(employees); await _context.SaveChangesAsync(); return RedirectToAction(nameof(Index)); } return View(employees); }
public async Task <IActionResult> Create([Bind("PmEpicId,PmEpicName")] PmEpics pmEpics) { if (ModelState.IsValid) { _context.Add(pmEpics); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(pmEpics)); }
public async Task <IActionResult> Create([Bind("ProductID,ProductName,SupplierID,CategoryID,QuantityPerUnit,UnitPrice,UnitsInStock,UnitsOnOrder,ReorderLevel,Discontinued")] ProductsModel productsModel) { if (ModelState.IsValid) { _context.Add(productsModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(productsModel)); }
public async Task <IActionResult> Create([Bind("ShipperId,CompanyName,Phone")] Shippers shippers) { if (ModelState.IsValid) { _context.Add(shippers); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(shippers)); }
/// <summary> /// Registration with username, password and Customer id. /// </summary> /// <param name="userRegisterDTO">User model</param> /// <returns> /// Returns the result message of the request. /// </returns> public HttpResponseMessage Post([FromBody] UserRegisterDTO userRegisterDTO) { var response = new HttpResponseMessage(HttpStatusCode.OK); //check User have existing in database if (!(northwindContext.TbIuser.Any(u => u.Username.Equals(userRegisterDTO.Username))) && !(northwindContext.TbIuser.Any(u => u.CustomerId.Equals(userRegisterDTO.CustomerId)))) { ValidatorResult validatorResult = UserValidator.IsValidUser(userRegisterDTO); if (!validatorResult.IsValid) { response.StatusCode = HttpStatusCode.PreconditionFailed; response.Content = new StringContent(JsonConvert.SerializeObject(validatorResult.ValidationMessage)); return(response); } TbIuser user = new TbIuser(); user.Username = userRegisterDTO.Username.Trim(); var customer = northwindContext.Customers.Find(userRegisterDTO.CustomerId); if (customer == null) { response.StatusCode = HttpStatusCode.PreconditionFailed; response.Content = new StringContent(JsonConvert.SerializeObject("Wrong CustomerId.")); return(response); } user.CustomerId = userRegisterDTO.CustomerId; user.Salt = Convert.ToBase64String(Common.GetRandomSalt(16)); user.Password = Convert.ToBase64String(Common.SaltHashPassword( Encoding.ASCII.GetBytes(userRegisterDTO.Password), Convert.FromBase64String(user.Salt))); user.FullName = userRegisterDTO.FullName.Trim(); //Add to DB try { northwindContext.Add(user); northwindContext.SaveChanges(); response.Content = new StringContent(JsonConvert.SerializeObject("Register successfully")); return(response); } catch (Exception e) { response.StatusCode = HttpStatusCode.InternalServerError; response.Content = new StringContent(JsonConvert.SerializeObject(e.Message)); return(response); } } else { response.StatusCode = HttpStatusCode.PreconditionFailed; response.Content = new StringContent(JsonConvert.SerializeObject("User is existing in Database.")); return(response); } }
public async Task <IActionResult> Create([Bind("DepartmentID,DepartmentName,DepartmentDesc")] Department department) { if (ModelState.IsValid) { _context.Add(department); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(department)); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Title,BirthDate,City")] Empl empl) { if (ModelState.IsValid) { _context.Add(empl); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(empl)); }
public async Task <IActionResult> Create(Categories categories) { if (ModelState.IsValid) { _context.Add(categories); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(categories)); }
public async Task <IActionResult> Create([Bind("CustomerID,CompanyName,ContactName,ContactTitle,Address,City,Region,PostalCode,Country,Phone,Fax")] Customers customers) { if (ModelState.IsValid) { _context.Add(customers); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(customers)); }
public async Task <IActionResult> Create([Bind("Id,UserName,NormalizedUserName,Email,NormalizedEmail,EmailConfirmed,PasswordHash,SecurityStamp,ConcurrencyStamp,PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEnd,LockoutEnabled,AccessFailedCount")] AspNetUsers aspNetUsers) { if (ModelState.IsValid) { _context.Add(aspNetUsers); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(aspNetUsers)); }
public async Task <IActionResult> Create([Bind("CategoryId,CategoryName,Description,Picture")] Categories categories) { if (ModelState.IsValid) { _context.Add(categories); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(categories)); }
public async Task <IActionResult> Create([Bind("SupplierId,Address,City,CompanyName,ContactName,ContactTitle,Country,Fax,HomePage,Phone,PostalCode,Region")] Suppliers suppliers) { if (ModelState.IsValid) { _context.Add(suppliers); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(suppliers)); }
public async Task <IActionResult> Create([Bind("CustomerTypeId,CustomerDesc")] CustomerDemographics customerDemographics) { if (ModelState.IsValid) { _context.Add(customerDemographics); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(customerDemographics)); }
public async Task <IActionResult> Create([Bind("TerritoryId,TerritoryDescription,RegionId")] Territories territories) { if (ModelState.IsValid) { _context.Add(territories); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["RegionId"] = new SelectList(_context.Region, "RegionId", "RegionDescription", territories.RegionId); return(View(territories)); }
//[ValidateAntiForgeryToken] public async Task <IActionResult> Create(Region region) { if (ModelState.IsValid) { //_context.Region.Add(new Region { RegionDescription = region.RegionDescription }); _context.Add(region); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(region)); }
public async Task <IActionResult> Create([Bind("Id,Name,Phone,Type")] Parties parties) { if (ModelState.IsValid) { _context.Add(parties); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["Type"] = new SelectList(_context.PartyTypes, "Id", "Id", parties.Type); return(View(parties)); }
public int registrarUsuario(Tmusua m) { int sINSERT = 0; using (NorthwindContext _BD = new NorthwindContext()) { try { using (var transaccion = new TransactionScope()) { Tmusua sUsuario = _BD.Tmusua.Where(p => p.CoUsua == m.CoUsua).First(); if (sUsuario.CoUsua != m.CoUsua) { m.CoUsuaCrea = "DBA01"; m.CoUsuaModi = "DBA01"; m.StActi = "ACT"; //Para cifrar contraseña //SHA256Managed sha = new SHA256Managed(); //byte[] dataNoCifrada = Encoding.Default.GetBytes(m.NoClav); //byte[] dataCifafrada = sha.ComputeHash(dataNoCifrada); //string claveCifrada = BitConverter.ToString(dataCifafrada).Replace("-", ""); //m.NoClav = claveCifrada; _BD.Add(m); _BD.SaveChanges(); transaccion.Complete(); sINSERT = 1; } else { //Tmusua sUsuario = _BD.Tmusua.Where(p => p.CoUsua == m.CoUsua).First(); sUsuario.CoUsua = m.CoUsua; sUsuario.NoUsua = m.NoUsua; //sUsuario.NoClav = m.NoClav; sUsuario.CoGrup = m.CoGrup; sUsuario.CoUsuaModi = "DBA01"; sUsuario.DeDireMail = m.DeDireMail; _BD.SaveChanges(); transaccion.Complete(); sINSERT = 1; } } } catch (Exception) { sINSERT = 0; } return(sINSERT); } }