public JsonResult SaveQuotation(string data) { try { var model = JsonConvert.DeserializeObject <SalesDetailViewModel>(data); model.Invoice.UserId = User.Identity.GetUserId(); model.Invoice.Created = DateTime.Now; model.Invoice.InvoiceStatusId = (int)InvoiceStatus.Draft; foreach (Payment payment in model.Invoice.Payments) { payment.UserId = this.User.Identity.GetUserId(); } db.Invoices.Add(model.Invoice); db.SaveChanges(); return(Json(new { Result = true, Message = "New Invoice created successful", Data = new { InvoiceId = model.Invoice.Id } })); } catch (Exception ex) { var message = new StringBuilder(); message.AppendLine(ex.Message); Exception innerException = ex.InnerException; while (innerException != null) { message.AppendLine(string.IsNullOrWhiteSpace(innerException.Message) ? string.Empty : innerException.Message); innerException = innerException.InnerException; } return(Json(new { Result = false, Message = message.ToString() })); } }
public JsonResult Save(string data) { try { var model = JsonConvert.DeserializeObject <PurchaseOrderDetailViewModel>(data); model.PurchaseOrder.UserId = User.Identity.GetUserId(); model.PurchaseOrder.Created = DateTime.Now; model.PurchaseOrder.PurchaseOrderStatusId = 1; db.PurchaseOrders.Add(model.PurchaseOrder); db.SaveChanges(); return(Json(new { Result = true, Message = "New Purchase Order created successful", Data = new { PurchaseStatus = model.PurchaseOrder.Id } })); } catch (Exception ex) { var message = new StringBuilder(); message.AppendLine(ex.Message); Exception innerException = ex.InnerException; while (innerException != null) { message.AppendLine(string.IsNullOrWhiteSpace(innerException.Message) ? string.Empty : innerException.Message); innerException = innerException.InnerException; } return(Json(new { Result = false, Message = message.ToString() })); } }
public ActionResult DeleteConfirmed(string id) { AspNetUser aspNetUser = db.AspNetUsers.Find(id); db.AspNetUsers.Remove(aspNetUser); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "Id,Name")] PurchaseOrderStatu purchaseOrderStatu) { if (ModelState.IsValid) { db.PurchaseOrderStatus.Add(purchaseOrderStatu); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(purchaseOrderStatu)); }
public ActionResult Create([Bind(Include = "Id,Name")] Branch branch) { if (ModelState.IsValid) { db.Branches.Add(branch); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(branch)); }
public ActionResult Create([Bind(Include = "Key,Value")] Config config) { if (ModelState.IsValid) { db.Configs.Add(config); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(config)); }
public ActionResult Create([Bind(Include = "Id,BusinessName,ContactName,Email,Phone,Address,WorkingHours")] Provider provider) { if (ModelState.IsValid) { db.Providers.Add(provider); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(provider)); }
public ActionResult Create([Bind(Include = "Id,Name")] Category category) { if (ModelState.IsValid) { db.Categories.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult Create([Bind(Include = "Id,Name")] InvoiceStatu invoiceStatu) { if (ModelState.IsValid) { db.InvoiceStatus.Add(invoiceStatu); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(invoiceStatu)); }
public ActionResult Create([Bind(Include = "Id,Name")] AspNetRole aspNetRole) { if (ModelState.IsValid) { db.AspNetRoles.Add(aspNetRole); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(aspNetRole)); }
public ActionResult Create([Bind(Include = "Id,FirstName,MiddleName,LastName,Email,Phone,Address")] Client client) { if (ModelState.IsValid) { db.Clients.Add(client); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(client)); }
public ActionResult Create([Bind(Include = "Name")] PaymentType paymentType) { paymentType.Id = db.PaymentTypes.Max(p => p.Id + 1); if (ModelState.IsValid) { db.PaymentTypes.Add(paymentType); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(paymentType)); }
public ActionResult Create([Bind(Include = "Id,Name,BranchId")] Storage storage) { if (ModelState.IsValid) { db.Storages.Add(storage); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.BranchId = new SelectList(db.Branches, "Id", "Name", storage.BranchId); return(View(storage)); }
public ActionResult Create([Bind(Include = "Id,Name,StorageId")] Location location) { if (ModelState.IsValid) { db.Locations.Add(location); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.StorageId = new SelectList(db.Storages, "Id", "Name", location.StorageId); return(View(location)); }
public JsonResult Create([Bind(Include = "Id,Type,Date,Number,Name,Amount,ProviderId")] Supply supply) { try { db.Supplies.Add(supply); db.SaveChanges(); return(Json(new { Result = true, Data = supply }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { Result = false, Message = ex.Message }, JsonRequestBehavior.AllowGet)); } }
public JsonResult Create([Bind(Include = "Id,Type,Date,Number,Name,Split,OriginalAmount,PaidAmount,Description")] Utility utility) { try { db.Utilities.Add(utility); db.SaveChanges(); return(Json(new { Result = true, Data = utility }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { Result = false, Message = ex.Message }, JsonRequestBehavior.AllowGet)); } }
public ActionResult Create([Bind(Include = "Id,Date,Text,UserId,ClientId,Active")] ClientNote clientNote) { if (ModelState.IsValid) { db.ClientNotes.Add(clientNote); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.UserId = new SelectList(db.AspNetUsers, "Id", "Email", clientNote.UserId); ViewBag.ClientId = new SelectList(db.Clients, "Id", "FirstName", clientNote.ClientId); return(View(clientNote)); }
public JsonResult ConvertToInvoice(int id) { try { var invoice = db.Invoices.Find(id); invoice.InvoiceStatusId = 2; db.Entry(invoice).State = EntityState.Modified; db.SaveChanges(); return(Json(new { Result = true, Message = "Convert Estimate to Invoice success", InvoiceId = id })); } catch (Exception ex) { return(Json(new { Result = false, Message = ex.Message })); } }
public JsonResult Add(int clientId, string text) { try { var userId = User.Identity.GetUserId(); var client = db.Clients.Find(clientId); var note = new ClientNote() { Date = DateTime.Now, Text = text, ClientId = clientId, UserId = userId }; db.ClientNotes.Add(note); db.SaveChanges(); return(Json(new { Result = true, Data = new { Result = true, NoteId = note.Id, ClientId = note.ClientId } }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { Result = false, Message = ex.Message })); } }
public void ReceiveOrder(int orderId) { var order = db.PurchaseOrders .Include(po => po.PurchaseOrderDetails) .FirstOrDefault(po => po.Id == orderId); foreach (var detail in order.PurchaseOrderDetails) { var stockProduct = db.Stocks.FirstOrDefault(s => s.ProductId == detail.ProductId); if (stockProduct == null) { stockProduct = new Stock() { ProductId = detail.ProductId, LocationId = 1,//TODO: StockQuantity = detail.Quantity }; db.Stocks.Add(stockProduct); } else { stockProduct.StockQuantity += detail.Quantity; db.Entry(stockProduct).State = EntityState.Modified; } } db.SaveChanges(); }
public void ExtractFromStock(IEnumerable <InvoiceDetail> details) { if (details == null) { throw new ArgumentNullException("The list of products can't be empty"); } foreach (var detail in details) { if (db.Stocks.Any(s => s.ProductId == detail.ProductId)) { var stockProduct = db.Stocks.FirstOrDefault(s => s.ProductId == detail.ProductId); if ((stockProduct.StockQuantity - detail.Quantity) < 0) { throw new Exception(string.Format("There is not enough product for attend to this order(Product Quantity{0}", stockProduct.StockQuantity)); } stockProduct.StockQuantity -= detail.Quantity - detail.InOrder; db.Entry(stockProduct).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } }
public JsonResult Add(Log log) { try { log.Created = DateTime.Now; log.UserId = User.Identity.GetUserId(); if (ModelState.IsValid) { db.Logs.Add(log); db.SaveChanges(); return(Json(new { Result = true })); } return(Json(new { Result = false, Message = "There are some invalid fields" })); } catch (Exception ex) { return(Json(new { Result = false, Message = ex.Message })); } }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, MiddleName = model.MiddleName }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { var db = new XFModel(); db.Logs.Add(new Log() { UserId = User.Identity.GetUserId(), Created = DateTime.Now, Message = string.Format("Adding user | data: {0}", JsonConvert.SerializeObject(new { UserName = model.Email, Name = user.FullName })), Type = "success" }); db.SaveChanges(); // 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("Index", "Users")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Create([Bind(Include = "Id,Code,Name,Display,SellPrice,PurchasePrice,Max,Min,ProviderId,CategoryId")] Product product) { if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ProviderId = new SelectList(db.Providers .ToList() .Select(p => new { Id = p.Id, Name = p.BusinessName }) , "Id", "Name"); ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", product.CategoryId) .ToList(); return(View(product)); }