public HttpResponseMessage Post([FromBody] ProductosClasificacion pc) { try { ProductosClasificacion Consulta = db.ProductosClasificacion.Where(a => a.CodClasificacion == pc.CodClasificacion).FirstOrDefault(); if (Consulta == null) { db.ProductosClasificacion.Add(pc); db.SaveChanges(); resp = new { Success = true }; return(Request.CreateResponse(HttpStatusCode.OK, resp)); } else { throw new Exception("Clasificacion ya existe"); } } catch (Exception ex) { // EncuestasRegistroController.GuardarBitacoraTxt(ex.Message); return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public void Add(TEntityDTO entity) { var mappedEntity = Mapper.Map <TEntity>(entity); Db.Set <TEntity>().Add(mappedEntity); Db.SaveChanges(); }
public HttpResponseMessage Post([FromBody] Clientes cliente) { try { Clientes Consulta = db.Clientes.Where(a => a.CodCliente == cliente.CodCliente).FirstOrDefault(); if (Consulta == null) { db.Clientes.Add(cliente); db.SaveChanges(); resp = new { Success = true }; return(Request.CreateResponse(HttpStatusCode.OK, resp)); } else { throw new Exception("Cliente ya existe"); } } catch (Exception ex) { // EncuestasRegistroController.GuardarBitacoraTxt(ex.Message); return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public ActionResult Delete(ListItemViewModel model) { using (POSContext context = new POSContext()) { using (var dbTransaction = context.Database.BeginTransaction()) { int UserId = User.Identity.GetUserId <int>(); int OutletId = 0; OutletId = (int)EmployeeOutletDAL.GetDataOutletByUserId(UserId).OutletID; int i = 0; foreach (var item in model.InventoryId) { ItemsIventory data3 = context.TItemsIventory.Where(x => x.ID == item).FirstOrDefault(); context.TItemsIventory.Remove(data3); try { context.SaveChanges(); } catch (Exception) { } i++; } i = 0; foreach (var item in model.VariantId) { ItemsVariant data2 = context.TItemsVariant.Where(x => x.ID == item).FirstOrDefault(); context.TItemsVariant.Remove(data2); try { context.SaveChanges(); } catch (Exception) { } i++; } Items data = context.TItems.Where(x => x.ID == model.ID).FirstOrDefault(); context.TItems.Remove(data); try { context.SaveChanges(); } catch (Exception) { } try { dbTransaction.Commit(); return(RedirectToAction("Index")); } catch (Exception) { dbTransaction.Rollback(); } } } return(PartialView("Delete", model)); }
public ActionResult Create(Category category) { if (ModelState.IsValid) { db.Categorys.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult Create(User user) { if (ModelState.IsValid) { db.Users.Add(user); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public ActionResult Detail(ListPurchaseOrderViewModel model) { if (ModelState.IsValid) { using (POSContext context = new POSContext()) { using (var dbTransacyion = context.Database.BeginTransaction()) { int UserId = User.Identity.GetUserId <int>(); PurchaseOrder item = context.TPurchaseOrder.Where(m => m.ID == model.ID).FirstOrDefault(); item.StatusID = model.StatusID; item.ModifiedBy = UserId; item.ModifiedOn = DateTime.Now; context.SaveChanges(); PurchaseOrderHistory item2 = new PurchaseOrderHistory() { HeaderID = item.ID, StatusID = model.StatusID, CreatedBy = UserId, ModifiedBy = UserId, CreatedOn = DateTime.Now, ModifiedOn = DateTime.Now }; context.TPurchaseOrderHistory.Add(item2); context.SaveChanges(); if (model.StatusID == 2) { int i = 0; foreach (var data in model.VariantID) { int variantid = data; ItemsIventory item3 = context.TItemsIventory.Where(m => m.VariantID == variantid).FirstOrDefault(); item3.PurchaseOrder = model.Quantity[i]; i++; } context.SaveChanges(); } try { dbTransacyion.Commit(); return(RedirectToAction("Index")); } catch (Exception) { throw; } } } } return(PartialView("Detail", model)); }
public ActionResult Create(Product product) { if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.brandID = new SelectList(db.Brands, "brandID", "brandName", product.brandID); return(View(product)); }
public ActionResult Create(Brand brand) { if (ModelState.IsValid) { db.Brands.Add(brand); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.categoryID = new SelectList(db.Categorys, "categoryID", "categoryName", brand.categoryID); return(View(brand)); }
public void TestUpsertProductModifiers() { TestHandler.Handle((DbContextOptions <POSContext> options) => { var productId = 1; using (var context = new POSContext(options)) { context.CreateProductData(); context.CreateModifierData(total: 2, totalItemModifier: 2); context.SaveChanges(); context.Add(new ProductModifier { ModifierId = 1, ProductId = 1 }); context.SaveChanges(); var dto = new List <ProductModifier>() { new ProductModifier { ProductId = productId, ModifierId = 1 }, new ProductModifier { ProductId = productId, ModifierId = 2 }, }; //assert add one more var productService = new ProductService(context); var product = productService.GetProduct(productId).Result; productService.UpsertDeleteProductModifiers(product, dto); context.SaveChanges(); Assert.AreEqual(2, context.Product.FirstOrDefault().ProductModifier.Count()); } using (var context = new POSContext(options)) { //asssert remove all var dto = new List <ProductModifier>() { }; var productService = new ProductService(context); var product2 = productService.GetProduct(productId).Result; productService.UpsertDeleteProductModifiers(product2, dto); context.SaveChanges(); Assert.AreEqual(0, context.Product.FirstOrDefault().ProductModifier.Count()); } }); }
public HttpResponseMessage Post([FromBody] ProductosViewModel producto) { try { Productos Consulta = db.Productos.Where(a => a.Codpro == producto.Codpro).FirstOrDefault(); if (Consulta == null) { Consulta = new Productos(); if (!String.IsNullOrEmpty(producto.ImagenBase64)) { string Url = GuardaImagenBase64(producto.ImagenBase64, "Productos", producto.Codpro + "_" + producto.CodBarras + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg); Consulta.Imagen = Url; } else { Consulta.Imagen = Consulta.Imagen; } Consulta.Codpro = producto.Codpro; Consulta.CodCla = producto.CodCla; Consulta.Descripcion = producto.Descripcion; Consulta.CodBarras = producto.CodBarras; Consulta.Cantidad = producto.Cantidad; Consulta.Nompro = producto.Nompro; Consulta.Precio = producto.Precio; Consulta.Activo = true; Consulta.FechaCreacion = DateTime.Now; db.Productos.Add(Consulta); db.SaveChanges(); resp = new { Success = true }; return(Request.CreateResponse(HttpStatusCode.OK, resp)); } else { throw new Exception("Producto ya existe"); } } catch (Exception ex) { // EncuestasRegistroController.GuardarBitacoraTxt(ex.Message); return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public ActionResult Delete(CategoriesViewModel model) { if (ModelState.IsValid) { using (POSContext context = new POSContext()) { bool isSave = false; var VOutlet = context.TOutlet.ToList(); foreach (var item in VOutlet) { Categories Kategori = context.TCategories.Where(m => m.Name == model.Name).FirstOrDefault(); context.TCategories.Remove(Kategori); try { context.SaveChanges(); isSave = true; } catch (Exception) { isSave = false; } } if (isSave == true) { return(RedirectToAction("Index")); } } } return(PartialView("Delete", model)); }
// ListItems yang akan diambil ini disesuaikan dengan kategori ID public ActionResult UpdateItems(CategoriesViewModel models) { using (POSContext context = new POSContext()) { int i = 0; //var userId = User.Identity.GetUserId<int>(); //int OutletId = 0; foreach (var item in models.ItemID) { Items data = context.TItems.Where(x => x.ID == item).FirstOrDefault(); if (data != null) { data.CategoryID = models.ID; } i++; } try { context.SaveChanges(); return(RedirectToAction("Index"));; } catch (Exception) { throw; }; } }
public ActionResult Create(ViewModel model) { //if (ModelState.IsValid) //{ // using (var context = new POSContext()) // { // var address = from c in context.Addresses // where c.Id == model.AddressId // select c; // var customer = new Customer(model.Customer.LastName, model.Customer.FirstName, (Address)address, model.Customer.EmailAddress); // context.Customers.Add(customer); // context.SaveChanges(); // return RedirectToAction("Index"); // } //} using (var context = new POSContext()) { var id = Convert.ToInt32(model.AddressId); var q = from c in context.Addresses where c.Id == id select c; var customer = new Customer(model.Customer.LastName, model.Customer.FirstName, (Address)q.First(), model.Customer.EmailAddress); context.Customers.Add(customer); context.SaveChanges(); return(RedirectToAction("Index")); } }
private static POSContext AddItem(POSContext context, POSItems item) { if (!context.Items.Any(e => e.Id == item.Id)) { context.Add(item); context.SaveChanges(); } return(context); }
public async Task <HttpResponseMessage> PostAsync([FromBody] Proforma proforma) { var transaccion = db.Database.BeginTransaction(); try { EncProforma Consulta = db.EncProforma.Where(a => a.NumProforma == proforma.encProforma.NumProforma).FirstOrDefault(); if (Consulta == null) { proforma.encProforma.FecFactura = DateTime.Now; db.EncProforma.Add(proforma.encProforma); await db.SaveChangesAsync(); foreach (var det in proforma.detProforma) { det.NumProforma = proforma.encProforma.NumProforma; det.Nompro = det.Nompro; //db.Productos.Where(a => a.Codpro == det.Codpro).Select(u => u.Nompro).FirstOrDefault(); db.DetProforma.Add(det); db.SaveChanges(); } transaccion.Commit(); resp = new { Success = true }; return(Request.CreateResponse(HttpStatusCode.OK, resp)); } else { throw new Exception("Producto ya existe"); } } catch (Exception ex) { transaccion.Rollback(); // EncuestasRegistroController.GuardarBitacoraTxt(ex.Message); return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public static void CreateProductData(this POSContext context, int total = 1) { for (int i = 0; i < total; i++) { context.Add(new Product() { Name = $"Prod{(i + 1)}" }); } context.SaveChanges(); }
public HttpResponseMessage Post([FromBody] Usuarios cliente) { try { Usuarios Consulta = db.Usuarios.Where(a => a.Nombre.ToLower().Contains(cliente.Nombre.ToLower())).FirstOrDefault(); if (Consulta == null) { Usuarios Usr = new Usuarios(); Usr.Nombre = cliente.Nombre; Usr.idRol = cliente.idRol; Usr.Clave = BCrypt.Net.BCrypt.HashPassword(cliente.Clave); Usr.Activo = true; db.Usuarios.Add(Usr); db.SaveChanges(); resp = new { Success = true }; return(Request.CreateResponse(HttpStatusCode.OK, resp)); } else { throw new Exception("Usuario ya existe"); } } catch (Exception ex) { // EncuestasRegistroController.GuardarBitacoraTxt(ex.Message); return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public async Task <ActionResult> Pay([FromBody] OrderForPayDTO vm) { //save to order, orderDetail, paymentOrder var order = _mapper.Map <Order>(vm); //check that products are for rent if (TryValidateModel(order)) { _context.Add(order); _context.SaveChanges(); return(Ok()); } return(BadRequest(ModelState)); }
public int Complete() { try { return(_context.SaveChanges()); } catch (System.Data.Entity.Infrastructure.DbUpdateException ex) { throw ex; } catch (Exception exc) { throw exc; } }
// GET: Summary public ActionResult Index() { List <ItemIventoryViewModel> model = ItemIventoryDAL.GetDataSum(); using (POSContext context = new POSContext()) foreach (var item in model) { ItemsIventory data = context.TItemsIventory.Where(m => m.ID == item.ID).FirstOrDefault(); data.Ending = item.Beginning + item.PurchaseOrder + item.Adjusment - item.Sales - item.Transfer; context.SaveChanges(); } return(View(model)); }
public void SaveOrder(Order order) { lock (syncRoot) { try { int id; order.DailyNumber = GetDailyNum(); this.Add(order); id = _context.SaveChanges(); } catch (Exception ex) { throw ex; } } }
public ActionResult Delete(SuppliersViewModel model) { using (POSContext context = new POSContext()) { Suppliers item = context.TSuppliers.Where(x => x.ID == model.ID).FirstOrDefault(); context.TSuppliers.Remove(item); try { context.SaveChanges(); return(Json(new { success = true })); } catch (Exception) { throw; } } }
public ActionResult Add(CategoriesViewModel model) { int UserId = User.Identity.GetUserId <int>(); if (ModelState.IsValid) { using (POSContext context = new POSContext()) { bool isSave = false; var VOutlet = context.TOutlet.ToList(); foreach (var item in VOutlet) { Categories Kategori = new Categories() { Name = model.Name, OutletID = item.ID, CreatedBy = UserId, CreatedOn = DateTime.Now, ModifiedBy = UserId, ModifiedOn = DateTime.Now, }; context.TCategories.Add(Kategori); try { context.SaveChanges(); isSave = true; } catch (Exception) { isSave = false; } } if (isSave == true) { return(RedirectToAction("Index")); } } } return(PartialView("Add", model)); }
public ActionResult Edit(CategoriesViewModel model) { int UserId = User.Identity.GetUserId <int>(); if (ModelState.IsValid) { using (POSContext context = new POSContext()) { bool isSave = false; var VOutlet = context.TOutlet.ToList(); foreach (var item in VOutlet) { Categories Kategori = context.TCategories.Where(m => m.Name == model.Name).FirstOrDefault(); Kategori.Name = model.Name2; Kategori.CreatedBy = UserId; Kategori.CreatedOn = DateTime.Now; Kategori.ModifiedBy = UserId; Kategori.ModifiedOn = DateTime.Now; try { context.SaveChanges(); isSave = true; } catch (Exception) { isSave = false; } } if (isSave == true) { return(RedirectToAction("Index")); } } } return(PartialView("Edit", model)); }
public ActionResult Add(SuppliersViewModel model) { var userId = User.Identity.GetUserId <int>(); if (ModelState.IsValid) { using (POSContext context = new POSContext()) { Suppliers item = new Suppliers() { ID = model.ID, Name = model.Name, Address = model.Address, ProvinceID = model.ProvinceID, RegionID = model.RegionID, DistrictID = model.DistrictID, PostalCode = model.PostalCode, Phone = model.Phone, Email = model.Email, CreatedBy = userId, CreatedOn = DateTime.Now, ModifiedBy = userId, ModifiedOn = DateTime.Now, }; context.TSuppliers.Add(item); try { context.SaveChanges(); return(Json(new { success = "true" })); } catch (Exception) { throw; } } } return(PartialView("Add", model)); }
public ActionResult Add(CustomersViewModel model) { if (ModelState.IsValid) { using (POSContext context = new POSContext()) { Customers item = new Customers() { ID = model.ID, CustomerName = model.CustomerName, Email = model.Email, Phone = model.Phone, Address = model.Address, BirthDate = model.BirthDate, CreatedBy = 1, CreatedOn = DateTime.Now, ModifiedBy = 1, ModifiedOn = DateTime.Now, ProvinceID = model.ProvinceID, RegionID = model.RegionID, DistrictID = model.DistrictID, }; context.TCustomers.Add(item); try { context.SaveChanges(); return(RedirectToAction("Add", "Payment")); } catch (Exception) { throw; } } } return(PartialView("Add", model)); }
public ActionResult Edit(SuppliersViewModel model) { int UserId = User.Identity.GetUserId <int>(); if (ModelState.IsValid) { using (POSContext context = new POSContext()) { Suppliers item = context.TSuppliers.Where(x => x.ID == model.ID).FirstOrDefault(); item.ID = model.ID; item.Name = model.Name; item.Address = model.Address; item.ProvinceID = model.ProvinceID; item.RegionID = model.RegionID; item.DistrictID = model.DistrictID; item.Email = model.Email; item.Phone = model.Phone; item.CreatedOn = DateTime.Now; item.CreatedBy = UserId; item.ModifiedOn = DateTime.Now; item.ModifiedBy = UserId; try { context.SaveChanges(); return(Json(new { success = true })); } catch (Exception) { throw; } } } return(PartialView("Edit", model)); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); //return RedirectToAction("Register"); using (POSContext context = new POSContext()) { using (var dbTransaction = context.Database.BeginTransaction()) { Employee item = new Employee() { Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, Title = model.Title, CreatedBy = 1, CreatedOn = DateTime.Now, ModifiedBy = 1, ModifiedOn = DateTime.Now }; context.TEmployee.Add(item); try { context.SaveChanges(); } catch (Exception) { } EmployeeOutlet vEOutlet = new EmployeeOutlet() { EmployeeID = item.ID, OutletID = model.OutletID, RoleID = model.RoleID, CreatedBy = 1, CreatedOn = DateTime.Now, ModifiedBy = 1, ModifiedOn = DateTime.Now }; context.TEmployeeOutlet.Add(vEOutlet); context.SaveChanges(); try { dbTransaction.Commit(); return(RedirectToAction("Register")); } catch (Exception) { dbTransaction.Rollback(); } } } } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public void Add(User entity) { _posContext.Users.Add(entity); _posContext.SaveChanges(); }