コード例 #1
0
        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() }));
            }
        }
コード例 #2
0
 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() }));
     }
 }
コード例 #3
0
        public ActionResult DeleteConfirmed(string id)
        {
            AspNetUser aspNetUser = db.AspNetUsers.Find(id);

            db.AspNetUsers.Remove(aspNetUser);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #4
0
        public ActionResult Create([Bind(Include = "Id,Name")] PurchaseOrderStatu purchaseOrderStatu)
        {
            if (ModelState.IsValid)
            {
                db.PurchaseOrderStatus.Add(purchaseOrderStatu);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(purchaseOrderStatu));
        }
コード例 #5
0
ファイル: BranchesController.cs プロジェクト: Yoadad/FX
        public ActionResult Create([Bind(Include = "Id,Name")] Branch branch)
        {
            if (ModelState.IsValid)
            {
                db.Branches.Add(branch);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(branch));
        }
コード例 #6
0
        public ActionResult Create([Bind(Include = "Key,Value")] Config config)
        {
            if (ModelState.IsValid)
            {
                db.Configs.Add(config);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(config));
        }
コード例 #7
0
        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));
        }
コード例 #8
0
ファイル: CategoriesController.cs プロジェクト: Yoadad/FX
        public ActionResult Create([Bind(Include = "Id,Name")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
コード例 #9
0
ファイル: InvoiceStatusController.cs プロジェクト: Yoadad/FX
        public ActionResult Create([Bind(Include = "Id,Name")] InvoiceStatu invoiceStatu)
        {
            if (ModelState.IsValid)
            {
                db.InvoiceStatus.Add(invoiceStatu);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(invoiceStatu));
        }
コード例 #10
0
ファイル: RolesController.cs プロジェクト: Yoadad/FX
        public ActionResult Create([Bind(Include = "Id,Name")] AspNetRole aspNetRole)
        {
            if (ModelState.IsValid)
            {
                db.AspNetRoles.Add(aspNetRole);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(aspNetRole));
        }
コード例 #11
0
ファイル: ClientsController.cs プロジェクト: Yoadad/FX
        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));
        }
コード例 #12
0
ファイル: PaymentTypesController.cs プロジェクト: Yoadad/FX
        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));
        }
コード例 #13
0
        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));
        }
コード例 #14
0
ファイル: LocationsController.cs プロジェクト: Yoadad/FX
        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));
        }
コード例 #15
0
ファイル: SuppliesController.cs プロジェクト: Yoadad/FX
 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));
     }
 }
コード例 #16
0
 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));
     }
 }
コード例 #17
0
ファイル: ClientNotesController.cs プロジェクト: Yoadad/FX
        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));
        }
コード例 #18
0
 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 }));
     }
 }
コード例 #19
0
ファイル: NotesController.cs プロジェクト: Yoadad/FX
        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 }));
            }
        }
コード例 #20
0
        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();
        }
コード例 #21
0
ファイル: StockController.cs プロジェクト: Yoadad/FX
        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();
                }
            }
        }
コード例 #22
0
 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 }));
     }
 }
コード例 #23
0
ファイル: AccountController.cs プロジェクト: Yoadad/FX
        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));
        }
コード例 #24
0
        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));
        }