Esempio n. 1
0
        public ActionResult Edit(int id)
        {
            var repo       = new InvoiceRepository(_context);
            var invoice    = repo.GetById(id);
            var clientRepo = new ClientRepository(_context);
            var formModel  = new EditInvoice()
            {
                Id            = id,
                ClientId      = invoice.ClientId,
                InvoiceNumber = invoice.InvoiceNumber,
                ClientList    = clientRepo.GetSelectListItems(),
                DateOpened    = invoice.DateOpened
            };

            return(View(formModel));
        }
Esempio n. 2
0
        public async Task <IActionResult> EditInvoice(EditInvoice editInvoice)
        {
            if (ModelState.IsValid)
            {
                var dbInvoice = dbContext.Invoices.FirstOrDefault(x => x.id == editInvoice.id);

                if (!string.IsNullOrEmpty(editInvoice.StoreName) &&
                    !string.IsNullOrEmpty(editInvoice.InvoiceProductType) &&
                    (editInvoice.InvoiceProductAmount != 0 || editInvoice.InvoiceProductAmount != null) &&
                    (editInvoice.InvoiceProductPrice != 0 || editInvoice.InvoiceProductPrice != null) &&
                    !string.IsNullOrEmpty(editInvoice.InvoiceFollowCode))
                {
                    dbInvoice.StoreName            = editInvoice.StoreName;
                    dbInvoice.InvoiceProductType   = editInvoice.InvoiceProductType;
                    dbInvoice.InvoiceProductAmount = editInvoice.InvoiceProductAmount;
                    dbInvoice.InvoiceFollowCode    = editInvoice.InvoiceFollowCode;
                    dbInvoice.DeliveryOffice       = editInvoice.DeliveryOffice;
                    dbInvoice.InvoiceComments      = editInvoice.InvoiceComments;
                    dbInvoice.InvoiceProductPrice  = editInvoice.InvoiceProductPrice;
                }


                //======================================== If there is any image submitted then this image is added to folder
                if (editInvoice.FormFile != null)
                {
                    var nameOfImage      = Path.GetFileNameWithoutExtension(editInvoice.FormFile.FileName);
                    var extensionOfImage = Path.GetExtension(editInvoice.FormFile.FileName);
                    var guid             = Guid.NewGuid();

                    var newFileName = nameOfImage + guid + extensionOfImage;


                    var rootPath = Path.Combine(webHost.WebRootPath, "Invoice", "InvoiceGallery", newFileName);

                    using (var fileStream = new FileStream(rootPath, FileMode.Create))
                    {
                        editInvoice.FormFile.CopyTo(fileStream);
                    }

                    dbInvoice.FileName = newFileName;
                }

                dbContext.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Esempio n. 3
0
        public ActionResult Edit(int id, EditInvoice formModel)
        {
            var invoice = new Invoice()
            {
                Id            = id,
                ClientId      = formModel.ClientId,
                InvoiceNumber = formModel.InvoiceNumber,
                DateOpened    = formModel.DateOpened
            };
            var repo = new InvoiceRepository(_context);

            try
            {
                repo.Update(invoice);
                return(RedirectToAction("Details", "Invoices",
                                        routeValues: new { id = id })); // This is so weird
            }
            catch (Exception e)                                         // Squashing exceptions is never a good idea
            {
                // TODO Handle exception
                return(View(formModel));
            }
        }