示例#1
0
        public async Task <Object> UpdateCustomer(Customer updatedCustomer)
        {
            try
            {
                Customer customer = await _dbContext.Customers.FindAsync(updatedCustomer.CustomerID);

                customer.Company          = updatedCustomer.Company;
                customer.PhoneNo          = updatedCustomer.PhoneNo;
                customer.Fax              = updatedCustomer.Fax;
                customer.Address1         = updatedCustomer.Address1;
                customer.Address2         = updatedCustomer.Address2;
                customer.City             = updatedCustomer.City;
                customer.Province         = updatedCustomer.Province;
                customer.PostalCode       = updatedCustomer.PostalCode;
                customer.Comments         = updatedCustomer.Comments;
                customer.Country          = updatedCustomer.Country;
                customer.DekSmartDiscount = updatedCustomer.DekSmartDiscount;
                customer.GSTExempt        = updatedCustomer.GSTExempt;
                customer.PSTExempt        = updatedCustomer.PSTExempt;
                customer.ShipCharges      = updatedCustomer.ShipCharges;
                customer.Packaging        = updatedCustomer.Packaging;
                customer.Modified         = DateTime.UtcNow;
                await _dbContext.SaveChangesAsync();

                return(new { success = true, responseText = "Customer Saved" });
            }
            catch (Exception ex)
            {
                return(new { success = false, responseText = "Customer Save Failed" });
            }
        }
        public async Task <ActionResult> Index([Bind(Include = "PartID,AltPartID,Name,Description,ProductLineID,PartStatusID,CustomFlag,Comments,ModifiedDate,Weight,Height,Width,Length,MeasUnitID,PartInventoryID")] Part part, [Bind(Include = "PartID,ValidStart,ValidEnd,DateCreated,CostValue,CostCurrencyID,SellValue,SellCurrencyID,EmployeeID")] Price price, string CategoryID)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    price.PriceID = new Random().Next();
                    var date = DateTime.Today;
                    part.Files = FilesController.listSelectedFiles;
                    if (ImagesController.Image != null)
                    {
                        if (!string.IsNullOrEmpty(ImagesController.Image.Name))
                        {
                            part.Image   = ImagesController.Image;
                            part.ImageID = ImagesController.Image.ImageID;
                        }
                    }
                    part.PriceID      = price.PriceID;
                    part.CreatedDate  = date;
                    part.EmployeeID   = 1;
                    part.ModifiedDate = date;
                    part.CategoryID   = db.Categories.Where(n => n.Name == CategoryID).Select(i => i.CategoryID).FirstOrDefault();
                    part.Category     = db.Categories.Where(cat => cat.Name == CategoryID).FirstOrDefault();
                    db.Parts.Add(part);

                    await db.SaveChangesAsync();



                    price.PartID      = part.PartID;
                    price.EmployeeID  = 1;
                    price.DateCreated = date;
                    db.Prices.Add(price);
                    await db.SaveChangesAsync();


                    return(RedirectToAction("Index", "Home", null));
                }
                else
                {
                    Session["TmpModel"] = ViewData.ModelState;
                    return(RedirectToAction("Index", "Home", null));
                }
            }
            catch (Exception e)
            {
                var s = e.Message;
            }

            //ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "Name", part.CategoryID);
            //ViewBag.MeasUnitID = new SelectList(db.MeasUnits, "MeasUnitID", "ShortDescription", part.MeasUnitID);
            //ViewBag.PartStatusID = new SelectList(db.PartStatus, "PartStatusID", "Status", part.PartStatusID);
            //ViewBag.ProductLineID = new SelectList(db.ProductLines, "ProductLineID", "Name", part.ProductLineID);


            return(View(part));
        }
 public async Task <ActionResult> DeleteImg(int ImageID)
 {
     if (Image != null)
     {
         db.Images.Remove(db.Images.Where(n => n.ImageID == ImageID).FirstOrDefault());
         Image = null;
         await db.SaveChangesAsync();
     }
     return(PartialView("_SaveUploadedFile", Image));
 }
        public async Task <ActionResult> delete(string name)
        {
            var file = listFiles.Find(i => i.Name == name);

            if (file != null)
            {
                listFiles.Remove(file);
                listSelectedFiles.Remove(listSelectedFiles.Find(i => i.Name == file.Name));
                db.FilesTmp.Remove(db.FilesTmp.Where(n => n.ID == file.ID).FirstOrDefault());
                await db.SaveChangesAsync();
            }
            return(PartialView("_SaveUploadedFile"));
        }
 public async Task <ActionResult> Create([Bind(Include = "Name, CategoryParentID")] Category category)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (category != null)
             {
                 db.Categories.Add(category);
                 await db.SaveChangesAsync();
             }
             else
             {
                 return(Json(new { warning = "category is null" }));
             }
         }
         else
         {
             return(Json(new { warning = "model is not valid" }));
         }
     }
     catch (Exception e)
     {
         ModelState.AddModelError("", e.Message);
         return(View(category));
     }
     return(RedirectToAction("Index", "Home"));
 }
 public async Task <ActionResult> Create([Bind(Include = "Name, Description")] ProductLine productLine)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (productLine != null)
             {
                 db.ProductLines.Add(productLine);
                 await db.SaveChangesAsync();
             }
             else
             {
                 return(Json(new { warning = "ProductLines is null" }));
             }
         }
         else
         {
             return(Json(new { warning = "model is not valid" }));
         }
     }
     catch (Exception e)
     {
         ModelState.AddModelError("", e.Message);
         return(View(productLine));
     }
     return(RedirectToAction("Index", "Home"));
 }
 public async Task <ActionResult> Create([Bind(Include = "ShortDescription, LongDescription")] MeasUnit measUnit)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (measUnit != null)
             {
                 db.MeasUnits.Add(measUnit);
                 await db.SaveChangesAsync();
             }
             else
             {
                 return(Json(new { warning = "status is null" }));
             }
         }
         else
         {
             return(Json(new { warning = "model is not valid" }));
         }
     }
     catch (Exception e)
     {
         ModelState.AddModelError("", e.Message);
         return(View(measUnit));
     }
     return(RedirectToAction("Index", "Home"));
 }
 public async Task <ActionResult> Create([Bind(Include = "Status")] PartStatu partStatu)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (partStatu != null)
             {
                 db.PartStatus.Add(partStatu);
                 await db.SaveChangesAsync();
             }
             else
             {
                 return(Json(new { warning = "status is null" }));
             }
         }
         else
         {
             return(Json(new { warning = "model is not valid" }));
         }
     }
     catch (Exception e)
     {
         return(Json(new { warning = e.Message }));
     }
     return(RedirectToAction("Index", "Home"));
 }
示例#9
0
        public async Task <int> AddCarrier(Carrier newCarrier)
        {
            _dbContext.Carriers.Add(newCarrier);

            try
            {
                await _dbContext.SaveChangesAsync();
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException ex)
            {
                System.Diagnostics.Debug.WriteLine("{0}{1}Validation errors:{1}{2}", ex, Environment.NewLine, ex.EntityValidationErrors.Select(e => string.Join(Environment.NewLine, e.ValidationErrors.Select(v => string.Format("{0} - {1}", v.PropertyName, v.ErrorMessage)))));

                throw;
            }

            return(newCarrier.CarrierID);
        }
        public async Task <int> AddShippingAddress(ShippingAddress newShippingAddress)
        {
            newShippingAddress.LastUsed = DateTime.Now;
            _dbContext.ShippingAddresses.Add(newShippingAddress);

            try
            {
                await _dbContext.SaveChangesAsync();
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException ex)
            {
                System.Diagnostics.Debug.WriteLine("{0}{1}Validation errors:{1}{2}", ex, Environment.NewLine, ex.EntityValidationErrors.Select(e => string.Join(Environment.NewLine, e.ValidationErrors.Select(v => string.Format("{0} - {1}", v.PropertyName, v.ErrorMessage)))));

                throw;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }

            return(newShippingAddress.ShippingAddressID);
        }
        public async Task <ActionResult> PartCreate(
            [Bind(Include = "PartID,CategoryID,AltPart,Name,Description,ProductLineID,PartStatusID,CustomFlag,Comments,ModifiedDate,Weight,Height,Width,Length,MeasUnitID,PartInventoryID")] Part part,
            [Bind(Include = "PartID,DateCreated,CostValue,CostCurrencyID,SellValue,SellCurrencyID,EmployeeID")] Price price,
            string CategoryName, string startdate, string finishdate)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    price.PriceID = new Random().Next();
                    var date = DateTime.Today;
                    part.Files = listSelectedFiles;
                    if (Image != null)
                    {
                        if (!string.IsNullOrEmpty(Image.Name))
                        {
                            part.Image   = Image;
                            part.ImageID = Image.ImageID;
                        }
                    }
                    part.PartID       = new Random().Next();
                    part.PriceID      = price.PriceID;
                    part.CreatedDate  = date;
                    part.EmployeeID   = 1;
                    part.ModifiedDate = date;
                    part.CategoryID   = db.Categories.Where(n => n.Name == CategoryName).Select(i => i.CategoryID).FirstOrDefault();
                    part.Category     = db.Categories.Where(cat => cat.Name == CategoryName).FirstOrDefault();
                    part.MeasUnit     = db.MeasUnits.Where(p => p.MeasUnitID == part.MeasUnitID).FirstOrDefault();
                    db.Parts.Add(part);

                    await db.SaveChangesAsync();


                    price.PartID      = part.PartID;
                    price.EmployeeID  = 1;
                    price.DateCreated = date;
                    price.ValidStart  = DateTime.ParseExact(startdate, "dd.MM.yyyy",
                                                            System.Globalization.CultureInfo.InvariantCulture);
                    price.ValidEnd = DateTime.ParseExact(finishdate, "dd.MM.yyyy",
                                                         System.Globalization.CultureInfo.InvariantCulture);
                    db.Prices.Add(price);
                    await db.SaveChangesAsync();

                    ViewBag.ProductLineID  = new SelectList(db.ProductLines, "ProductLineID", "Name");
                    ViewBag.MeasUnitID     = new SelectList(db.MeasUnits, "MeasUnitID", "ShortDescription");
                    ViewBag.PartStatusID   = new SelectList(db.PartStatus, "PartStatusID", "Status");
                    ViewBag.CostCurrencyID = new SelectList(db.Currencies, "CurrencyID", "Name");
                    ViewBag.SellCurrencyID = new SelectList(db.Currencies, "CurrencyID", "Name");
                    var cust = (from p in db.CustomerContacts
                                select new { id = p.CustomerID, name = p.First }).Distinct();

                    ViewBag.CustomerID = new SelectList(cust, "id", "name");

                    foreach (var item in listFiles)
                    {
                        string filePath = Path.Combine(Server.MapPath(@"~/Images/WallFiles/filepath"), item.Name + '.' + item.Type);

                        if (System.IO.File.Exists(filePath))
                        {
                            System.IO.File.Delete(filePath);
                        }
                    }
                    string imagePath = Path.Combine(Server.MapPath(@"~/Images/WallImages/imagepath"), Image.Name + '.' + Image.Ext);

                    if (System.IO.File.Exists(imagePath))
                    {
                        System.IO.File.Delete(imagePath);
                    }
                    listFiles.Clear();
                    listSelectedFiles.Clear();

                    return(View("Index"));
                }
                else
                {
                    Session["TmpModel"] = ViewData.ModelState;
                    return(View("Index"));
                }
            }
            catch (Exception e)
            {
                var s = e.Message;
            }

            return(View("Index"));
        }