public async Task <IActionResult> Create(PSouvenir souvenir)
        {
            if (ModelState.IsValid)
            {
                var sou = new Souvenir();
                using (var ms = new MemoryStream())
                {
                    await souvenir.image.CopyToAsync(ms);

                    sou.SouImage       = ms.ToArray();
                    sou.SouQuantity    = souvenir.SouQuantity;
                    sou.SouDescription = souvenir.SouDescription;
                    sou.SouName        = souvenir.SouName;
                    sou.SouPrice       = souvenir.SouPrice;
                    sou.SupplierID     = souvenir.SupplierID;
                    sou.CategoryID     = souvenir.CategoryID;
                }

                _context.Add(sou);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryID"] = new SelectList(_context.Categories, "CategoryID", "CategoryID", souvenir.CategoryID);
            ViewData["SupplierID"] = new SelectList(_context.Suppliers, "SupplierID", "SupplierID", souvenir.SupplierID);
            return(View(souvenir));
        }
コード例 #2
0
        public ActionResult DeleteItem(string name)
        {
            List <Souvenir> ShoppingBag; // reference to null

            if (Session["Cart"] == null) // the cart is empty!
            {
                Session.Add("Cart", new List <Souvenir>());

                ShoppingBag = new List <Souvenir>();
            }

            else// user has items in the cart, so go and retrive it!
            {
                ShoppingBag = (List <Souvenir>)Session["Cart"];
            }
            ///////////////////////////



            Souvenir Option = ShoppingBag.Find(x => x.Souvenirname == name);

            ShoppingBag.Remove(Option);

            Session["Cart"] = ShoppingBag;// save changes you made to your cart!


            ViewBag.Cart = ShoppingBag;



            return(View("Cart"));
        }
コード例 #3
0
        public async Task <IHttpActionResult> PutSouvenir(int id, Souvenir souvenir)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != souvenir.Id)
            {
                return(BadRequest());
            }
            souvenir.Timestamp       = DateTime.Now;
            db.Entry(souvenir).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SouvenirExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #4
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name,Description,Price,PathOfImage,SupplierName,CategoryName")] Souvenir souvenir, IList <IFormFile> _files)
        {
            ViewData["CategoryName"] = new SelectList(_context.Set <Category>(), "Name", "Name");
            ViewData["SupplierName"] = new SelectList(_context.Set <Supplier>(), "Name", "Name");

            if (id != souvenir.ID)
            {
                return(NotFound());
            }

            var relativeName = "";
            var fileName     = souvenir.PathOfImage;

            if (_files.Count < 1)
            {
                relativeName = "/images/Souvenirs/Default.png";
            }
            else
            {
                foreach (var file in _files)
                {
                    fileName = ContentDispositionHeaderValue
                               .Parse(file.ContentDisposition)
                               .FileName
                               .Trim('"');
                    //Path for localhost
                    relativeName = "/images/Souvenirs/" + fileName;

                    using (FileStream fs = System.IO.File.Create(_hostingEnv.WebRootPath + relativeName))
                    {
                        await file.CopyToAsync(fs);

                        fs.Flush();
                    }
                }
            }
            souvenir.PathOfImage = fileName;

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(souvenir);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SouvenirExists(souvenir.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(souvenir));
        }
コード例 #5
0
        public async Task <IActionResult> Create([Bind("SouvenirID,Name,Description,Price,CategoryID,SupplierID")] Souvenir souvenir, IFormFile uploadFile)
        {
            if (ModelState.IsValid)
            {
                var userId = _userManager.GetUserId(User);

                if (uploadFile != null && uploadFile.Length > 0)
                {
                    var fileName = Path.GetFileName(uploadFile.FileName);
                    var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\images\\items", fileName);
                    using (var fileStream = new FileStream(filePath, FileMode.Create))
                    {
                        await uploadFile.CopyToAsync(fileStream);
                    }
                    souvenir.PathOfFile = fileName;
                }
                _context.Add(souvenir);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryID"] = new SelectList(_context.Categories, "CategoryID", "Name", souvenir.CategoryID);
            ViewData["SupplierID"] = new SelectList(_context.Suppliers, "SupplierID", "EmailAddress", souvenir.SupplierID);
            return(View(souvenir));
        }
コード例 #6
0
        public async Task <IActionResult> Edit(int id, [Bind("SouvenirID,Name,Description,SupplierID,CategoryID,Price,ImagePath")] Souvenir souvenir)
        {
            if (id != souvenir.SouvenirID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(souvenir);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SouvenirExists(souvenir.SouvenirID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryID"] = new SelectList(_context.Categories, "CategoryID", "Name", souvenir.CategoryID);
            ViewData["SupplierID"] = new SelectList(_context.Suppliers, "SupplierID", "Name", souvenir.SupplierID);
            return(View(souvenir));
        }
コード例 #7
0
        //
        // GET: /Store/AddToCart/5
        //public ActionResult AddToCart(int id)
        public async Task <IActionResult> AddToCart(int?id, string RV)
        {
            byte[] rowVersion = Convert.FromBase64String(RV);
            // Retrieve the album from the database
            var addedSouvenir = await _context.Souvenirs
                                .SingleOrDefaultAsync(souvenir => souvenir.SouvenirID == id);

            if (addedSouvenir == null)
            {
                Souvenir deletedSouvenir = new Souvenir();
                await TryUpdateModelAsync(deletedSouvenir);

                return(RedirectToAction("Index", "MemberSouvenirs", new { error = "deleted" }));
            }
            if (BitConverter.ToString(rowVersion) != BitConverter.ToString(addedSouvenir.RowVersion))
            {
                this.EmptyCart();
                return(RedirectToAction("Index", "MemberSouvenirs", new { error = "updated", rv = addedSouvenir.RowVersion }));
            }

            _context.Entry(addedSouvenir).Property("RowVersion").OriginalValue = rowVersion;
            if (await TryUpdateModelAsync <Souvenir>(
                    addedSouvenir, "",
                    s => s.SouvenirName, s => s.Price, s => s.PhotoPath,
                    s => s.PhotoPath, s => s.Description, s => s.CategoryID,
                    s => s.SupplierID))
            {
                try
                {
                    // Go back to the main store page for more shopping
                    await _context.SaveChangesAsync();

                    // Add it to the shopping cart
                    var cart = ShoppingCart.GetCart(this.HttpContext);
                    cart.AddToCart(addedSouvenir, _context);
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    var exceptionEntry = ex.Entries.Single();
                    var clientValues   = (Souvenir)exceptionEntry.Entity;
                    var databaseEntry  = exceptionEntry.GetDatabaseValues();
                    if (databaseEntry == null)
                    {
                        return(RedirectToAction("Index", "MemberSouvenirs", new { error = "deleted" }));
                    }
                    else
                    {
                        var databaseValues = (Souvenir)databaseEntry.ToObject();
                        addedSouvenir.RowVersion = (byte[])databaseValues.RowVersion;
                        ModelState.Remove("RowVersion");
                        return(RedirectToAction("Index", "MemberSouvenirs", new { error = "updated", rv = databaseValues.RowVersion }));
                    }
                }
            }
            return(RedirectToAction("Index", "MemberSouvenirs"));
        }
コード例 #8
0
        public async Task <IHttpActionResult> GetSouvenir(int id)
        {
            Souvenir souvenir = await db.Souvenirs.FindAsync(id);

            if (souvenir == null)
            {
                return(NotFound());
            }

            return(Ok(souvenir));
        }
コード例 #9
0
        public async Task <IHttpActionResult> PostSouvenir(Souvenir souvenir)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            souvenir.Timestamp = DateTime.Now;
            db.Souvenirs.Add(souvenir);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = souvenir.Id }, souvenir));
        }
コード例 #10
0
        public async Task <IActionResult> Create([Bind("ID,Name,Price,Description,SupplierID,CategoryID,Image")] Souvenir souvenir, IList <IFormFile> _files)
        {
            var relativeName = "";
            var fileName     = "";

            if (_files.Count < 1)
            {
                relativeName = "/images/Default.jpg";
            }
            else
            {
                foreach (var file in _files)
                {
                    fileName = ContentDispositionHeaderValue
                               .Parse(file.ContentDisposition)
                               .FileName
                               .Trim('"');
                    //Path for localhost
                    relativeName = "/images/products/" + DateTime.Now.ToString("ddMMyyyy-HHmmssffffff") + fileName;

                    using (FileStream fs = System.IO.File.Create(_hostingEnv.WebRootPath + relativeName))
                    {
                        await file.CopyToAsync(fs);

                        fs.Flush();
                    }
                }
            }
            souvenir.Image = relativeName;
            //Week 2
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(souvenir);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                //log the error
                ModelState.AddModelError("", "Unable to save changes." +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator");
            }

            ViewData["CategoryID"] = new SelectList(_context.Categories, "ID", "Name", souvenir.CategoryID);
            ViewData["SupplierID"] = new SelectList(_context.Suppliers, "ID", "Name", souvenir.SupplierID);
            return(View(souvenir));
        }
コード例 #11
0
        public async Task <IActionResult> Create([Bind("SouvenirID,Name,Description,SupplierID,CategoryID,Price,ImagePath")] Souvenir souvenir)
        {
            if (ModelState.IsValid)
            {
                _context.Add(souvenir);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryID"] = new SelectList(_context.Categories, "CategoryID", "Name", souvenir.CategoryID);
            ViewData["SupplierID"] = new SelectList(_context.Suppliers, "SupplierID", "Name", souvenir.SupplierID);
            return(View(souvenir));
        }
コード例 #12
0
        public async Task <IActionResult> Create([Bind("SouvenirName,Price,PhotoPath,Description,CategoryID,SupplierID")] Souvenir souvenir, IList <IFormFile> _files)
        {
            var relativeName = "";
            var fileName     = "";

            if (_files.Count < 1)
            {
                relativeName = "/images/Souvenir.svg";
            }
            else
            {
                foreach (var file in _files)
                {
                    fileName = ContentDispositionHeaderValue
                               .Parse(file.ContentDisposition)
                               .FileName
                               .Trim('"');
                    //Path for localhost
                    relativeName = "/images/SouvenirImages/" + DateTime.Now.ToString("ddMMyyyy-HHmmssffffff") + fileName;

                    using (FileStream fs = System.IO.File.Create(_hostingEnv.WebRootPath + relativeName))
                    {
                        await file.CopyToAsync(fs);

                        fs.Flush();
                    }
                }
            }
            souvenir.PhotoPath = relativeName;
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(souvenir);
                    await _context.SaveChangesAsync();

                    loadViewData();
                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            loadViewData();
            return(View(souvenir));
        }
コード例 #13
0
        public async Task <IHttpActionResult> DeleteSouvenir(int id)
        {
            Souvenir souvenir = await db.Souvenirs.FindAsync(id);

            if (souvenir == null)
            {
                return(NotFound());
            }

            db.Souvenirs.Remove(souvenir);
            await db.SaveChangesAsync();

            return(Ok(souvenir));
        }
コード例 #14
0
        public async Task <IActionResult> Edit(int id, [Bind("SouvenirID,Name,Description,Price,PathOfFile,CategoryID,SupplierID")] Souvenir souvenir, IFormFile uploadFile)
        {
            if (id != souvenir.SouvenirID)
            {
                return(NotFound());
            }

            var file = "";

            if (ModelState.IsValid)
            {
                try
                {
                    if (uploadFile != null && uploadFile.Length > 0)
                    {
                        var fileName = Path.GetFileName(uploadFile.FileName);
                        var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\images\\items", fileName);
                        using (var fileStream = new FileStream(filePath, FileMode.Create))
                        {
                            await uploadFile.CopyToAsync(fileStream);
                        }
                        souvenir.PathOfFile = fileName;
                    }
                    else
                    {
                        file = souvenir.PathOfFile;
                    }
                    souvenir.PathOfFile = file;

                    _context.Update(souvenir);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SouvenirExists(souvenir.SouvenirID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryID"] = new SelectList(_context.Categories, "CategoryID", "Name", souvenir.CategoryID);
            ViewData["SupplierID"] = new SelectList(_context.Suppliers, "SupplierID", "EmailAddress", souvenir.SupplierID);
            return(View(souvenir));
        }
コード例 #15
0
        public IHttpActionResult SetReccomended(ChbInfoModel chbmodel)
        {
            Souvenir souvenir = (from c in db.Souvenirs where c.Id == chbmodel.ChbCheckedId select c).FirstOrDefault();

            if (chbmodel.ChbChecked)
            {
                souvenir.Recommended = true;
            }
            else
            {
                souvenir.Recommended = false;
            }
            db.SaveChanges();
            return(Ok());
        }
コード例 #16
0
        public async Task <IActionResult> Create([Bind("ID,Name,Description,Price,PathOfImage,SupplierName,CategoryName")] Souvenir souvenir, IList <IFormFile> _files)
        {
            ViewData["CategoryName"] = new SelectList(_context.Set <Category>(), "Name", "Name");
            ViewData["SupplierName"] = new SelectList(_context.Set <Supplier>(), "Name", "Name");
            var relativeName = "";
            var fileName     = "";

            if (_files.Count < 1)
            {
                relativeName = "/images/Souvenirs/Default.png";
            }
            else
            {
                foreach (var file in _files)
                {
                    fileName = ContentDispositionHeaderValue
                               .Parse(file.ContentDisposition)
                               .FileName
                               .Trim('"');
                    //Path for localhost
                    relativeName = "/images/Souvenirs/" + fileName;

                    using (FileStream fs = System.IO.File.Create(_hostingEnv.WebRootPath + relativeName))
                    {
                        await file.CopyToAsync(fs);

                        fs.Flush();
                    }
                }
            }
            souvenir.PathOfImage = fileName;
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(souvenir);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator.");
            }
            return(View(souvenir));
        }
コード例 #17
0
        /*public async Task<IActionResult> Create([Bind("ID,Name,Price,Image,Description,CategoryID,SupplierID")] Souvenir souvenir)
         * {
         *  if (ModelState.IsValid)
         *  {
         *      _context.Add(souvenir);
         *      await _context.SaveChangesAsync();
         *      return RedirectToAction(nameof(Index));
         *  }
         *  return View(souvenir);
         * }*/

        public async Task <IActionResult> Create([Bind("Name, Price, Description, CategoryID, SupplierID")] Souvenir souvenir, IList <IFormFile> _files)
        {
            var relativeName = "";
            var fileName     = "";

            if (_files.Count < 1)
            {
                relativeName = "/Images/Souvenir/Default.jpg";
            }
            else
            {
                foreach (var file in _files)
                {
                    fileName = ContentDispositionHeaderValue
                               .Parse(file.ContentDisposition)
                               .FileName
                               .Trim('"');
                    relativeName = "/Images/Souvenir/" + DateTime.Now.ToString("ddMMyyyy-HHmmssffffff") + fileName;

                    using (FileStream fs =
                               System.IO.File.Create(_hostingEnv.WebRootPath + relativeName))
                    {
                        await file.CopyToAsync(fs);

                        fs.Flush();
                    }
                }
            }
            souvenir.Image = relativeName;
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(souvenir);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException)
            {
                ModelState.AddModelError("", "Unable to save changes." + "Try again and if the problem persists" + "see your system administrator.");
            }
            PopulateCategoriesDropDownList(souvenir.CategoryID);
            PopulateSuppliersDropDownList(souvenir.SupplierID);
            return(View(souvenir));
        }
        public async Task <IActionResult> Edit(int id, EditSouvenir souvenir)
        {
            if (id != souvenir.SouvenirID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var sou = new Souvenir();
                    using (var ms = new MemoryStream())
                    {
                        await souvenir.image.CopyToAsync(ms);

                        sou.SouvenirID     = souvenir.SouvenirID;
                        sou.SouImage       = ms.ToArray();
                        sou.SouQuantity    = souvenir.SouQuantity;
                        sou.SouDescription = souvenir.SouDescription;
                        sou.SouName        = souvenir.SouName;
                        sou.SouPrice       = souvenir.SouPrice;
                        sou.SupplierID     = souvenir.SupplierID;
                        sou.CategoryID     = souvenir.CategoryID;
                    }
                    _context.Update(sou);
                    await _context.SaveChangesAsync();
                }

                catch (DbUpdateConcurrencyException)
                {
                    if (!SouvenirExists(souvenir.SouvenirID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryID"] = new SelectList(_context.Categories, "CategoryID", "CategoryID", souvenir.CategoryID);
            ViewData["SupplierID"] = new SelectList(_context.Suppliers, "SupplierID", "SupplierID", souvenir.SupplierID);
            return(View(souvenir));
        }
コード例 #19
0
        public async Task <IActionResult> Create([Bind("Name,Price,Description,Image,SupplierID,CategoryID")] Souvenir souvenir)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(souvenir);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(souvenir));
        }
コード例 #20
0
        public async Task <IActionResult> Delete(Souvenir souvenir)
        {
            try
            {
                if (await _context.Souvenirs.AnyAsync(s => s.SouvenirID == souvenir.SouvenirID))
                {
                    _context.Souvenirs.Remove(souvenir);
                    await _context.SaveChangesAsync();
                }

                return(RedirectToAction("Index"));
            }
            catch (DbUpdateConcurrencyException)
            {
                return(RedirectToAction(nameof(Delete), new { concurrencyError = true, id = souvenir.SouvenirID }));
            }
            catch (DbUpdateException)
            {
                TempData["SouvenirUsed"] = "The Souvenir is in previous orders. Delete those orders and try again.";
                return(RedirectToAction("Delete"));
            }
        }
コード例 #21
0
 public async Task <IActionResult> Delete(Souvenir souvenir)
 {
     try
     {
         if (await _context.Souvenirs.AnyAsync(m => m.SouvenirID == souvenir.SouvenirID))
         {
             _context.Souvenirs.Remove(souvenir);
             await _context.SaveChangesAsync();
         }
         return(RedirectToAction(nameof(Index)));
     }
     catch (DbUpdateConcurrencyException /* ex */)
     {
         //Log the error (uncomment ex variable name and write a log.)
         return(RedirectToAction(nameof(Delete), new { concurrencyError = true, id = souvenir.SouvenirID }));
     }
     catch (DbUpdateException)
     {
         TempData["UserUsed"] = "The Souvenir being deleted has been ordered in previous orders.Delete those orders before trying again.";
         return(RedirectToAction("Delete"));
     }
 }
コード例 #22
0
        public ActionResult AddtoCart(string Souvenir)
        {
            List <Souvenir> ShoppingBag; // reference to null

            if (Session["Cart"] == null) // the cart is empty!
            {
                Session.Add("Cart", new List <Souvenir>());

                ShoppingBag = new List <Souvenir>();
            }

            else// user has items in the cart, so go and retrive it!
            {
                ShoppingBag = (List <Souvenir>)Session["Cart"];
            }
            ///////////////////////////
            maedbEntities2 ItemList = new maedbEntities2();


            Souvenir Option = ItemList.Souvenirs.Find(Souvenir);

            ShoppingBag.Add(Option);

            Session["Cart"] = ShoppingBag;// save changes you made to your cart!

            ViewBag.Cart = ShoppingBag;

            maedbEntities2  NewList     = new maedbEntities2();
            List <Souvenir> AllProducts = NewList.Souvenirs.ToList();

            ViewBag.PList = AllProducts;



            return(RedirectToAction("Product"));
        }
コード例 #23
0
        public static void Initialize(ApplicationDbContext context)
        {
            context.Database.EnsureCreated();

            //Look for any souvenirs
            if (context.Souvenirs.Any())
            {
                return;
            }

            var categories = new Category[] {
                new Category {
                    Name = "Maori Gifts", Description = "Traditional maori souvenirs"
                },
                new Category {
                    Name = "Mugs", Description = "Different kinds of mugs"
                },
                new Category {
                    Name = "T-Shirts", Description = "T-Shirts made in New Zealand "
                },
                new Category {
                    Name = "Home&Living", Description = "Home decorations"
                }
            };

            foreach (Category c in categories)
            {
                context.Categories.Add(c);
            }
            context.SaveChanges();

            var suppliers = new Supplier[] {
                new Supplier {
                    Name = "Ajay Kumar", PhoneNumber = "0212345679", Email = "*****@*****.**"
                },
                new Supplier {
                    Name = "Drego Alejaro ", PhoneNumber = "0243453263", Email = "*****@*****.**"
                },
                new Supplier {
                    Name = "Carl Flay", PhoneNumber = "0211212123", Email = "*****@*****.**"
                },
                new Supplier {
                    Name = "Andres Villacreces", PhoneNumber = "0276353535", Email = "*****@*****.**"
                },
                new Supplier {
                    Name = "Camila Rod", PhoneNumber = "02536374954", Email = "*****@*****.**"
                },
                new Supplier {
                    Name = "Carmen Maluenda", PhoneNumber = "0267834657", Email = "*****@*****.**"
                },
                new Supplier {
                    Name = "Cory Robert", PhoneNumber = "0275853565", Email = "*****@*****.**"
                },
                new Supplier {
                    Name = "Daniel Puentes", PhoneNumber = "0220664614", Email = "*****@*****.**"
                },
                new Supplier {
                    Name = "Diana Nino", PhoneNumber = "0210451297", Email = "*****@*****.**"
                },
                new Supplier {
                    Name = "Erika Abril", PhoneNumber = "0210515510", Email = "*****@*****.**"
                },
                new Supplier {
                    Name = "Douglas Baquero", PhoneNumber = "02108536902", Email = "*****@*****.**"
                }
            };

            foreach (Supplier s in suppliers)
            {
                context.Suppliers.Add(s);
            }
            context.SaveChanges();


            var souvenirs = new Souvenir[] {
                //Maori gifts
                new Souvenir {
                    Name  = "Maori Patu War Club 1", Price = 68, Description = "Traditional maori patu war club souvenir", SupplierID = 1, CategoryID = 1,
                    Image = "/images/products/maorigifts/patu-war-club1.jpg"
                },
                new Souvenir {
                    Name  = "Maori Patu War Club 2", Price = 68, Description = "Traditional maori patu war club souvenir", SupplierID = 1, CategoryID = 1,
                    Image = "/images/products/maorigifts/patu-war-club2.jpg"
                },
                new Souvenir {
                    Name  = "Maori Patu War Club 3", Price = 68, Description = "Traditional maori patu war club souvenir", SupplierID = 1, CategoryID = 1,
                    Image = "/images/products/maorigifts/patu-war-club3.jpg"
                },
                new Souvenir {
                    Name  = "Maori Wall Art 1", Price = 22, Description = "Maori wall art decorations", SupplierID = 1, CategoryID = 1,
                    Image = "/images/products/maorigifts/wall-arts-1.jpg"
                },
                new Souvenir {
                    Name  = "Maori Wall Art2", Price = 22, Description = "Maori wall art decorations", SupplierID = 1, CategoryID = 1,
                    Image = "/images/products/maorigifts/wall-arts-2.jpg"
                },
                new Souvenir {
                    Name  = "Maori Wall Art3", Price = 22, Description = "Maori wall art decorations", SupplierID = 1, CategoryID = 1,
                    Image = "/images/products/maorigifts/wall-arts-3.jpg"
                },
                new Souvenir {
                    Name  = "Pendants Earringgs", Price = 18, Description = "Maori Pendants earringgs for girls from any age", SupplierID = 1, CategoryID = 1,
                    Image = "/images/products/maorigifts/pendants-earringgs.jpg"
                },
                new Souvenir {
                    Name  = "Maori Patu", Price = 168, Description = "Traditional maori patu war club souvenir", SupplierID = 2, CategoryID = 1,
                    Image = "/images/products/maorigifts/patu-maori.jpg"
                },
                new Souvenir {
                    Name  = "Maori Necklace", Price = 49, Description = "maori necklace, a special gift for the coming Summer", SupplierID = 2, CategoryID = 1,
                    Image = "/images/products/maorigifts/maori-necklace.jpg"
                },
                new Souvenir {
                    Name  = "Maori Mask", Price = 88, Description = "maori style mask, suitable in festival", SupplierID = 2, CategoryID = 1,
                    Image = "/images/products/maorigifts/maori-mask.jpg"
                },
                new Souvenir {
                    Name  = "Maori Hook", Price = 23, Description = "Maori style hook for home decorations", SupplierID = 2, CategoryID = 1,
                    Image = "/images/products/maorigifts/maori-hook.jpg"
                },
                new Souvenir {
                    Name  = "Maori Gift box", Price = 58, Description = "Maori traditional gift box for little child", SupplierID = 2, CategoryID = 1,
                    Image = "/images/products/maorigifts/maori-gift-box.jpg"
                },
                new Souvenir {
                    Name  = "Maori Dolls", Price = 125, Description = "Little cute Maori style dolls", SupplierID = 2, CategoryID = 1,
                    Image = "/images/products/maorigifts/maori-dolls.jpg"
                },
                new Souvenir {
                    Name  = "Kotiate maori", Price = 36, Description = "Kotiate maori style decorations", SupplierID = 2, CategoryID = 1,
                    Image = "/images/products/maorigifts/kotiate-maori.jpg"
                },
                // Mugs
                new Souvenir {
                    Name  = "Anchored Direction", Price = 16, Description = "Must-buy, the essential goods in every day, make you in best mood.", SupplierID = 3, CategoryID = 2,
                    Image = "/images/products/mugs/anchored-direction-mug.jpg"
                },
                new Souvenir {
                    Name  = "Bride and Groom", Price = 16, Description = "Must-buy, the essential goods in every day, make you in best mood.", SupplierID = 3, CategoryID = 2,
                    Image = "/images/products/mugs/bride-and-groom-skeletons-mug.jpg"
                },
                new Souvenir {
                    Name  = "Dashing Through", Price = 16, Description = "Must-buy, the essential goods in every day, make you in best mood.", SupplierID = 3, CategoryID = 2,
                    Image = "/images/products/mugs/dashing-through-the-no-mug.jpg"
                },
                new Souvenir {
                    Name  = "Deep Space Diver", Price = 16, Description = "Must-buy, the essential goods in every day, make you in best mood.", SupplierID = 3, CategoryID = 2,
                    Image = "/images/products/mugs/deep-space-diver-mug.jpg"
                },
                new Souvenir {
                    Name  = "Caffeine Elixir", Price = 16, Description = "Must-buy, the essential goods in every day, make you in best mood.", SupplierID = 4, CategoryID = 2,
                    Image = "/images/products/mugs/dr-caffeine-elixir-mug.jpg"
                },
                new Souvenir {
                    Name  = "Dreamscape", Price = 16, Description = "Must-buy, the essential goods in every day, make you in best mood.", SupplierID = 4, CategoryID = 2,
                    Image = "/images/products/mugs/dreamscape-mug.jpg"
                },
                new Souvenir {
                    Name  = "Island Dream", Price = 16, Description = "Must-buy, the essential goods in every day, make you in best mood.", SupplierID = 4, CategoryID = 2,
                    Image = "/images/products/mugs/island-dream-mug.jpg"
                },
                new Souvenir {
                    Name  = "Just For You", Price = 16, Description = "Must-buy, the essential goods in every day, make you in best mood.", SupplierID = 3, CategoryID = 2,
                    Image = "/images/products/mugs/just-for-you-skeletons-mug.jpg"
                },
                new Souvenir {
                    Name  = "Just Married", Price = 16, Description = "Must-buy, the essential goods in every day, make you in best mood.", SupplierID = 3, CategoryID = 2,
                    Image = "/images/products/mugs/just-married-skeletons-mug.jpg"
                },
                new Souvenir {
                    Name  = "Kiwiana Mug", Price = 16, Description = "Must-buy, the essential goods in every day, make you in best mood.", SupplierID = 4, CategoryID = 2,
                    Image = "/images/products/mugs/kiwi-az-bro-kiwiana-mug.jpg"
                },
                new Souvenir {
                    Name  = "My Hearter", Price = 16, Description = "Must-buy, the essential goods in every day, make you in best mood.", SupplierID = 4, CategoryID = 2,
                    Image = "/images/products/mugs/kiwi-to-my-heart-kiwiana-mug.jpg"
                },
                new Souvenir {
                    Name  = "Mystery Island", Price = 16, Description = "Must-buy, the essential goods in every day, make you in best mood.", SupplierID = 3, CategoryID = 2,
                    Image = "/images/products/mugs/mystery-island-mug.jpg"
                },
                new Souvenir {
                    Name  = "The Island", Price = 16, Description = "Must-buy, the essential goods in every day, make you in best mood.", SupplierID = 3, CategoryID = 2,
                    Image = "/images/products/mugs/the-island-mug.jpg"
                },
                //T-shirts
                new Souvenir {
                    Name  = "NZ Style T-shirts", Price = 28, Description = "With New Zealand featured decorations, very special T-shirts 100% made in NZ", SupplierID = 5, CategoryID = 3,
                    Image = "/images/products/tshirts/nztshirts1.jpg"
                },
                new Souvenir {
                    Name  = "NZ Style T-shirts", Price = 28, Description = "With New Zealand featured decorations, very special T-shirts 100% made in NZ", SupplierID = 5, CategoryID = 3,
                    Image = "/images/products/tshirts/nztshirts2.jpg"
                },
                new Souvenir {
                    Name  = "NZ Style T-shirts", Price = 28, Description = "With New Zealand featured decorations, very special T-shirts 100% made in NZ", SupplierID = 5, CategoryID = 3,
                    Image = "/images/products/tshirts/nztshirts3.jpg"
                },
                new Souvenir {
                    Name  = "NZ Style T-shirts", Price = 28, Description = "With New Zealand featured decorations, very special T-shirts 100% made in NZ", SupplierID = 5, CategoryID = 3,
                    Image = "/images/products/tshirts/nztshirts4.jpg"
                },
                new Souvenir {
                    Name  = "NZ Style T-shirts", Price = 28, Description = "With New Zealand featured decorations, very special T-shirts 100% made in NZ", SupplierID = 5, CategoryID = 3,
                    Image = "/images/products/tshirts/nztshirts5.jpg"
                },
                new Souvenir {
                    Name  = "NZ Style T-shirts", Price = 28, Description = "With New Zealand featured decorations, very special T-shirts 100% made in NZ", SupplierID = 5, CategoryID = 3,
                    Image = "/images/products/tshirts/nztshirts6.jpg"
                },
                new Souvenir {
                    Name  = "NZ Style T-shirts", Price = 28, Description = "With New Zealand featured decorations, very special T-shirts 100% made in NZ", SupplierID = 6, CategoryID = 3,
                    Image = "/images/products/tshirts/nztshirts7.jpg"
                },
                new Souvenir {
                    Name  = "NZ Style T-shirts", Price = 28, Description = "With New Zealand featured decorations, very special T-shirts 100% made in NZ", SupplierID = 6, CategoryID = 3,
                    Image = "/images/products/tshirts/nztshirts8.jpg"
                },
                new Souvenir {
                    Name  = "NZ Style T-shirts", Price = 28, Description = "With New Zealand featured decorations, very special T-shirts 100% made in NZ", SupplierID = 6, CategoryID = 3,
                    Image = "/images/products/tshirts/nztshirts9.jpg"
                },
                new Souvenir {
                    Name  = "NZ Style T-shirts", Price = 28, Description = "With New Zealand featured decorations, very special T-shirts 100% made in NZ", SupplierID = 6, CategoryID = 3,
                    Image = "/images/products/tshirts/nztshirts10.jpg"
                },
                new Souvenir {
                    Name  = "NZ Style T-shirts", Price = 28, Description = "With New Zealand featured decorations, very special T-shirts 100% made in NZ", SupplierID = 6, CategoryID = 3,
                    Image = "/images/products/tshirts/nztshirts11.jpg"
                },
                new Souvenir {
                    Name  = "NZ Style T-shirts", Price = 28, Description = "With New Zealand featured decorations, very special T-shirts 100% made in NZ", SupplierID = 6, CategoryID = 3,
                    Image = "/images/products/tshirts/nztshirts12.jpg"
                },
                //Home&Living
                new Souvenir {
                    Name  = "Coaster", Price = 15, Description = "NZ made coster with maori features", SupplierID = 7, CategoryID = 4,
                    Image = "/images/products/homeandliving/coaster1.jpg"
                },
                new Souvenir {
                    Name  = "Coaster", Price = 15, Description = "NZ sightseeing coaster", SupplierID = 7, CategoryID = 4,
                    Image = "/images/products/homeandliving/coaster2.jpg"
                },
                new Souvenir {
                    Name  = "Coaster", Price = 15, Description = "Coster with cute owls", SupplierID = 7, CategoryID = 4,
                    Image = "/images/products/homeandliving/coaster3.jpg"
                },
                new Souvenir {
                    Name  = "Maori Draw Bag", Price = 17, Description = "Maori mix draw bags", SupplierID = 8, CategoryID = 4,
                    Image = "/images/products/homeandliving/maori-mix-draw-bags.jpg"
                },
                new Souvenir {
                    Name  = "Bolster", Price = 22, Description = "Soft bolster, warm your the whole winter", SupplierID = 8, CategoryID = 4,
                    Image = "/images/products/homeandliving/nzbolster.jpg"
                },
                new Souvenir {
                    Name  = "Ornament", Price = 19, Description = "Ornament for your home, best decorations.", SupplierID = 9, CategoryID = 4,
                    Image = "/images/products/homeandliving/ornament.jpg"
                },
                new Souvenir {
                    Name  = "Fridge Magnet", Price = 9, Description = "Rimu New Zealand native bird fridge magnet", SupplierID = 9, CategoryID = 4,
                    Image = "/images/products/homeandliving/rimu-new-zealand-native-bird-fridge-magnet.jpg"
                },
                new Souvenir {
                    Name  = "Treasure Box", Price = 32, Description = "Traditional Maori papahou treasure box", SupplierID = 10, CategoryID = 4,
                    Image = "/images/products/homeandliving/traditional-maori-papahou-treasure-box-paua-shell-lid.jpg"
                },
                new Souvenir {
                    Name  = "Wall Art", Price = 16, Description = "Local home wall art", SupplierID = 10, CategoryID = 4,
                    Image = "/images/products/homeandliving/wall-art1.jpg"
                },
                new Souvenir {
                    Name  = "Wall Art", Price = 16, Description = "Aroha wall art", SupplierID = 11, CategoryID = 4,
                    Image = "/images/products/homeandliving/wall-art2.jpg"
                },
                new Souvenir {
                    Name  = "Wood Ornament", Price = 19, Description = "Wood Ornament for your home, best decorations.", SupplierID = 11, CategoryID = 4,
                    Image = "/images/products/homeandliving/wood-ornament.jpg"
                }
            };

            foreach (Souvenir s in souvenirs)
            {
                context.Souvenirs.Add(s);
            }
            context.SaveChanges();
        }
コード例 #24
0
        public async Task <IActionResult> Edit(int?id, IList <IFormFile> _files, byte[] rowVersion)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var relativeName = "";
            var fileName     = "";
            var souvenir     = await _context.Souvenirs.SingleOrDefaultAsync(s => s.SouvenirID == id);

            if (souvenir == null)
            {
                Souvenir deleteSouvenir = new Souvenir();
                await TryUpdateModelAsync(deleteSouvenir);

                ModelState.AddModelError("", "The Souvenir is deleted by another user.");
                PopulateCategorySupplierDropDownList(deleteSouvenir.CategoryID, deleteSouvenir.SupplierID);
                return(View(deleteSouvenir));
            }
            if (_files.Count < 1)
            {
                relativeName = souvenir.PathOfFile;
            }
            else
            {
                foreach (var file in _files)
                {
                    fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition)
                               .FileName.Trim('"');
                    relativeName = "/Images/SouvenirImages/" + DateTime.Now.ToString("ddMMyyyy-HHmmssffffff") + fileName;
                    using (FileStream fs = System.IO.File.Create(_hostingEnv.WebRootPath + relativeName))
                    {
                        await file.CopyToAsync(fs);

                        fs.Flush();
                    }
                }
            }
            souvenir.PathOfFile = relativeName;

            _context.Entry(souvenir).Property("RowVersion").OriginalValue = rowVersion;
            if (await TryUpdateModelAsync(souvenir, "", s => s.Name, s => s.Description, s => s.CategoryID, s => s.SupplierID, s => s.Price))
            {
                try
                {
                    _context.Update(souvenir);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    var exceptionEntry = ex.Entries.Single();
                    var clientValues   = (Souvenir)exceptionEntry.Entity;
                    var databaseEntry  = exceptionEntry.GetDatabaseValues();
                    if (databaseEntry == null)
                    {
                        ModelState.AddModelError("", "The Souvenir is deleted by another user.");
                    }
                    else
                    {
                        var databaseValues = (Souvenir)databaseEntry.ToObject();
                        if (databaseValues.Name != clientValues.Name)
                        {
                            ModelState.AddModelError("Name", $"Currennt Value:{databaseValues.Name}");
                        }
                        if (databaseValues.Description != clientValues.Description)
                        {
                            ModelState.AddModelError("Description", $"Currennt Value:{databaseValues.Description}");
                        }
                        if (databaseValues.Price != clientValues.Price)
                        {
                            ModelState.AddModelError("Price", $"Currennt Value:{databaseValues.Price}");
                        }
                        if (databaseValues.PathOfFile != clientValues.PathOfFile)
                        {
                            ModelState.AddModelError("Image", $"Currennt Value:{databaseValues.PathOfFile}");
                        }
                        if (databaseValues.CategoryID != clientValues.CategoryID)
                        {
                            ModelState.AddModelError("CategoryID ", $"Currennt Value:{databaseValues.CategoryID }");
                        }
                        if (databaseValues.SouvenirID != clientValues.SouvenirID)
                        {
                            ModelState.AddModelError("SouvenirID", $"Currennt Value:{databaseValues.SupplierID}");
                        }
                        ModelState.AddModelError("", "The record is changed by another user.If you still want to edit Click save button");
                        souvenir.RowVersion = (byte[])databaseValues.RowVersion;
                        ModelState.Remove("RowVersion");
                    }
                }
            }
            PopulateCategorySupplierDropDownList(souvenir.CategoryID, souvenir.SupplierID);
            return(View(souvenir));
        }
コード例 #25
0
        public static void Initialize(SouvenirContext context)
        {
            context.Database.EnsureCreated();

            if (context.Souvenirs.Any())
            {
                return;
            }

            var customers = new Customer[]
            {
                new Customer {
                    FirstMidName      = "Customer1", LastName = "Test", HomePhoneNumber = "658265632", WorkPhoneNumber = "482975272658",
                    MobilePhoneNumber = "8795827591", Address = "Address1", Email = "*****@*****.**", Password = "******"
                }
            };

            foreach (Customer c in customers)
            {
                context.Customers.Add(c);
            }
            context.SaveChanges();

            var categories = new Category[]
            {
                new Category {
                    Name = "Maori Gifts"
                },
                new Category {
                    Name = "T-Shirts"
                },
                new Category {
                    Name = "Mugs"
                }
            };


            foreach (Category c in categories)
            {
                context.Categories.Add(c);
            }
            context.SaveChanges();

            var suppliers = new Supplier[]
            {
                new Supplier {
                    Name = "Mountain Jade", HomePhoneNumber = "12345678", WorkPhoneNumber = "87654321", MobilePhoneNumber = "321654987", Email = "*****@*****.**"
                },
                new Supplier {
                    Name = "Mr Vintage", HomePhoneNumber = "12345678", WorkPhoneNumber = "87654321", MobilePhoneNumber = "321654987", Email = "*****@*****.**"
                },
                new Supplier {
                    Name = "Simply New Zealand", HomePhoneNumber = "12345678", WorkPhoneNumber = "87654321", MobilePhoneNumber = "321654987", Email = "*****@*****.**"
                }
            };


            foreach (Supplier s in suppliers)
            {
                context.Suppliers.Add(s);
            }
            context.SaveChanges();

            var souvenirs = new Souvenir[]
            {
                new Souvenir {
                    Name      = "Koru Necklace", Description = "Greenstone, hand carved", SupplierID = 1, CategoryID = 1, Price = 150,
                    ImagePath = "images/KoruNecklace.jpg"
                },
                new Souvenir {
                    Name      = "Toki Blade Necklace", Description = "Greenstone, hand carved", SupplierID = 1, CategoryID = 1, Price = 76,
                    ImagePath = "images/TokiBlade.jpg"
                },
                new Souvenir {
                    Name      = "Pounamu Necklace", Description = "Greenstone, hand carved", SupplierID = 1, CategoryID = 1, Price = 228,
                    ImagePath = "images/Pounamu.jpg"
                },
                new Souvenir {
                    Name      = "Silver Disc Necklace", Description = "Greenstone, hand carved", SupplierID = 1, CategoryID = 1, Price = 149,
                    ImagePath = "images/SilverDisc.jpg"
                },
                new Souvenir {
                    Name      = "Canadian Jade Necklace", Description = "Single Twist Necklace", SupplierID = 1, CategoryID = 1, Price = 138,
                    ImagePath = "images/CanadianJade.jpg"
                },
                new Souvenir {
                    Name      = "NZ Jade Necklace", Description = "Large Twist Pendant", SupplierID = 1, CategoryID = 1, Price = 398,
                    ImagePath = "images/NZJadeLargeTwist.jpg"
                },


                new Souvenir {
                    Name      = "NZShirt", Description = "Gender Neutral T-shirt", SupplierID = 2, CategoryID = 2, Price = 30,
                    ImagePath = "images/NZShirt.jpg"
                },
                new Souvenir {
                    Name      = "All Good T-shirt", Description = "Gender Neutral T-shirt", SupplierID = 2, CategoryID = 2, Price = 30,
                    ImagePath = "images/AllGoodShirt.jpg"
                },
                new Souvenir {
                    Name      = "Hauraki Bhuja Hawk T-Shirt", Description = "Mens's T-shirt", SupplierID = 2, CategoryID = 2, Price = 30,
                    ImagePath = "images/BhujaHawk.jpg"
                },
                new Souvenir {
                    Name      = "Bros T-Shirt", Description = "Mens's T-shirt", SupplierID = 2, CategoryID = 2, Price = 30,
                    ImagePath = "images/BrosShirt.jpg"
                },
                new Souvenir {
                    Name      = "Double Brown T-Shirt", Description = "Gender Neutral T-shirt", SupplierID = 2, CategoryID = 2, Price = 30,
                    ImagePath = "images/DoubleBrownShirt.png"
                },
                new Souvenir {
                    Name      = "Kiwi Slang 90's T-Shirt", Description = "Gender Neutral T-shirt", SupplierID = 2, CategoryID = 2, Price = 30,
                    ImagePath = "images/KiwiSlangShirt.png"
                },


                new Souvenir {
                    Name      = "NZ Mug", Description = "Silver Fern Mug", SupplierID = 3, CategoryID = 3, Price = 15,
                    ImagePath = "images/NZMug.jpg"
                },
                new Souvenir {
                    Name      = "All Blacks Mug", Description = "Heat Activated Mug", SupplierID = 3, CategoryID = 3, Price = 15,
                    ImagePath = "images/NZMug.jpg"
                },
                new Souvenir {
                    Name      = "All Blacks Beer Handle", Description = "Frosted", SupplierID = 3, CategoryID = 3, Price = 15,
                    ImagePath = "images/AllBlacksBeer.jpg"
                },
                new Souvenir {
                    Name      = "Fantail Mug", Description = "Red", SupplierID = 3, CategoryID = 3, Price = 15,
                    ImagePath = "images/FantailMugRed.jpg"
                },
                new Souvenir {
                    Name      = "Kiwi Mug", Description = "Yellow", SupplierID = 3, CategoryID = 3, Price = 15,
                    ImagePath = "images/KiwiMugYellow.jpg"
                },
                new Souvenir {
                    Name      = "Pukeko Mug", Description = "Blue", SupplierID = 3, CategoryID = 3, Price = 15,
                    ImagePath = "images/PukekoMugBlue.png"
                },
            };

            foreach (Souvenir s in souvenirs)
            {
                context.Souvenirs.Add(s);
            }
            context.SaveChanges();

            var administrators = new Administrator[]
            {
                new Administrator {
                    AdministratorID = 1, AdminLoginName = "Admin", AdminPassword = "******"
                }
            };

            foreach (Administrator a in administrators)
            {
                context.Administrators.Add(a);
            }
            context.SaveChanges();
        }
コード例 #26
0
        public static void Initialize(ApplicationDbContext context)
        {
            if (context.Souvenirs.Any())
            {
                return;
            }



            var suppliers = new Supplier[] {
                new Supplier()
                {
                    FirstName = "Li", LastName = "Rock", Address = "49 Queen street", EmailAddress = "*****@*****.**", MobilePhoneNumber = "0251111111"
                },
                new Supplier()
                {
                    FirstName = "Green", LastName = "Jame", Address = "27 Bold Avenue", EmailAddress = "*****@*****.**", MobilePhoneNumber = "0251111112"
                },

                new Supplier()
                {
                    FirstName = "Kate", LastName = "Anny", Address = "31 Mt albert", EmailAddress = "*****@*****.**", MobilePhoneNumber = "0251111113"
                },
                new Supplier()
                {
                    FirstName = "Micheal", LastName = "Jack", Address = "22 Mandival Avenue", EmailAddress = "*****@*****.**", MobilePhoneNumber = "0251111114"
                },
                new Supplier()
                {
                    FirstName = "Owen", LastName = "Mick", Address = "22 Flatbush Avenue", EmailAddress = "*****@*****.**", MobilePhoneNumber = "0251111115"
                }
            };

            foreach (var item in suppliers)
            {
                context.Suppliers.Add(item);
            }
            context.SaveChanges();



            var categories = new Category[] {
                new Category()
                {
                    Name = "Maori Gift", Description = "The gifts from New Zealand"
                },
                new Category()
                {
                    Name = "Chinese Gift", Description = "The gifts from China"
                },
                new Category()
                {
                    Name = "Egyptian Gift", Description = "The gifts from Egypt"
                },
                new Category()
                {
                    Name = "Indian Gift", Description = "The gifts from India"
                },
                new Category()
                {
                    Name = "Roman Gift", Description = "The gifts from Roma"
                },
                new Category()
                {
                    Name = "Japanese Gift", Description = "The gifts from Japan"
                }
            };

            foreach (var item in categories)
            {
                context.Categories.Add(item);
            }
            context.SaveChanges();
            var souvenirs1 = new Souvenir[] {
                new Souvenir()
                {
                    Name = "Milk Wax", Description = "This is a Milk Wax", Price = 44, SupplierID = 1, CategoryID = 5, PathOfFile = "/Images/SouvenirImages/L30.jpg"
                },
                new Souvenir()
                {
                    Name = "Series Jewelries", Description = "This is a Series of Jewelries", Price = 2599, SupplierID = 4, CategoryID = 5, PathOfFile = "/Images/SouvenirImages/L33.jpg"
                },
                new Souvenir()
                {
                    Name = "Crystal", Description = "This is a Crystal", Price = 322, SupplierID = 2, CategoryID = 5, PathOfFile = "/Images/SouvenirImages/L36.jpg"
                },
                new Souvenir()
                {
                    Name = "Roma Cross", Description = "This is a Roma Cross", Price = 288, SupplierID = 2, CategoryID = 5, PathOfFile = "/Images/SouvenirImages/L37.jpg"
                },
                new Souvenir()
                {
                    Name = "Cat Necklace", Description = "This is a Cat Necklace", Price = 248, SupplierID = 4, CategoryID = 3, PathOfFile = "/Images/SouvenirImages/E30.jpg"
                },
                new Souvenir()
                {
                    Name = "Qipao China", Description = "This is a Qipao China", Price = 98, SupplierID = 1, CategoryID = 2, PathOfFile = "/Images/SouvenirImages/C32.jpg"
                }
            };

            foreach (var item in souvenirs1)
            {
                context.Souvenirs.Add(item);
            }
            context.SaveChanges();

            var souvenirs = new Souvenir[] {
                new Souvenir()
                {
                    Name = "Stone Carving", Description = "This is a Stone Carving", Price = 399, SupplierID = 3, CategoryID = 5, PathOfFile = "/Images/SouvenirImages/L02.jpg"
                },
                new Souvenir()
                {
                    Name = "Jade Bowl", Description = "This is a Jade Bowl", Price = 588, SupplierID = 3, CategoryID = 2, PathOfFile = "/Images/SouvenirImages/C16.jpg"
                },
                new Souvenir()
                {
                    Name = "Qing Necklace", Description = "This is a Qing Necklace", Price = 238, SupplierID = 3, CategoryID = 2, PathOfFile = "/Images/SouvenirImages/C30.jpg"
                },
                new Souvenir()
                {
                    Name = "Indian Ring", Description = "This is a Indian Ring", Price = 139, SupplierID = 2, CategoryID = 4, PathOfFile = "/Images/SouvenirImages/I30.jpg"
                },
                new Souvenir()
                {
                    Name = "Indian Pot", Description = "This is a Indian Pot", Price = 399, SupplierID = 3, CategoryID = 4, PathOfFile = "/Images/SouvenirImages/I31.jpg"
                },
                new Souvenir()
                {
                    Name = "Flower Necklace", Description = "This is a Flower Necklace", Price = 38, SupplierID = 2, CategoryID = 5, PathOfFile = "/Images/SouvenirImages/L34.jpg"
                },
                new Souvenir()
                {
                    Name = "Landscape Fan", Description = "This is a Landscape Fan", Price = 78, SupplierID = 3, CategoryID = 2, PathOfFile = "/Images/SouvenirImages/C13.jpg"
                },
                new Souvenir()
                {
                    Name = "Testacean Bowl", Description = "This is a Testacean Bowl", Price = 49, SupplierID = 1, CategoryID = 1, PathOfFile = "/Images/SouvenirImages/M09.jpg"
                },
                new Souvenir()
                {
                    Name = "Indian Necklace", Description = "This is an Indian Necklace", Price = 2999, SupplierID = 4, CategoryID = 4, PathOfFile = "/Images/SouvenirImages/I09.jpg"
                },
                new Souvenir()
                {
                    Name = "Wooden Dragon", Description = "This is a Wooden Dragon", Price = 238, SupplierID = 2, CategoryID = 2, PathOfFile = "/Images/SouvenirImages/C05.jpg"
                },
                new Souvenir()
                {
                    Name = "Sancai Horse", Description = "This is a Sancai horse from Tang Dynasty", Price = 4888, SupplierID = 2, CategoryID = 2, PathOfFile = "/Images/SouvenirImages/C15.jpg"
                },

                new Souvenir()
                {
                    Name = "Bone China", Description = "This is a Bone China", Price = 498, SupplierID = 4, CategoryID = 2, PathOfFile = "/Images/SouvenirImages/C17.jpg"
                },
                new Souvenir()
                {
                    Name = "Song teapot", Description = "This is a teapot from Sang Dynasty", Price = 7898, SupplierID = 1, CategoryID = 2, PathOfFile = "/Images/SouvenirImages/C18.jpg"
                },
                new Souvenir()
                {
                    Name = "Dragon Bottle", Description = "This is a Dragon Bottle", Price = 2238, SupplierID = 2, CategoryID = 2, PathOfFile = "/Images/SouvenirImages/C19.jpg"
                },
                new Souvenir()
                {
                    Name = "Opera Dolls", Description = "This is a pair of Opera Dolls", Price = 38, SupplierID = 3, CategoryID = 2, PathOfFile = "/Images/SouvenirImages/C20.jpg"
                },
                new Souvenir()
                {
                    Name = "Monkey King", Description = "This is a Monkey King doll", Price = 48, SupplierID = 4, CategoryID = 2, PathOfFile = "/Images/SouvenirImages/C21.jpg"
                },
                new Souvenir()
                {
                    Name = "Dony Model", Description = "This is a Dony Model", Price = 79, SupplierID = 5, CategoryID = 6, PathOfFile = "/Images/SouvenirImages/J01.jpg"
                },
                new Souvenir()
                {
                    Name = "Solong Model", Description = "This is a Solong Model", Price = 78, SupplierID = 2, CategoryID = 6, PathOfFile = "/Images/SouvenirImages/J03.jpg"
                },
                new Souvenir()
                {
                    Name = "Roman Building", Description = "This is Roma Building model", Price = 199, SupplierID = 2, CategoryID = 5, PathOfFile = "/Images/SouvenirImages/L01.jpg"
                },

                new Souvenir()
                {
                    Name = "Carving Women", Description = "This is a Stone Carving Women", Price = 99, SupplierID = 4, CategoryID = 5, PathOfFile = "/Images/SouvenirImages/L05.jpg"
                },
                new Souvenir()
                {
                    Name = "Sketch", Description = "This is a great painter's work which is a sketch of Audrey Hepburn", Price = 30, SupplierID = 2, CategoryID = 5, PathOfFile = "/Images/SouvenirImages/L06.jpg"
                },
                new Souvenir()
                {
                    Name = "Silver Hook", Description = "This is a Silver Hooked pendant", Price = 99, SupplierID = 1, CategoryID = 1, PathOfFile = "/Images/SouvenirImages/M01.jpg"
                },
                new Souvenir()
                {
                    Name = "Kiwi Bird", Description = "This is a Kiwi Bird pendant and a pair of earrings", Price = 189, SupplierID = 2, CategoryID = 1, PathOfFile = "/Images/SouvenirImages/M02.jpg"
                },
                new Souvenir()
                {
                    Name = "Wooden Totem", Description = "This is a Maori's unique Maori wooden totem", Price = 79, SupplierID = 3, CategoryID = 1, PathOfFile = "/Images/SouvenirImages/M03.jpg"
                },
                new Souvenir()
                {
                    Name = "Wooden Face", Description = "This is a Maori Wooden Face", Price = 39, SupplierID = 1, CategoryID = 1, PathOfFile = "/Images/SouvenirImages/M20.jpg"
                },
                new Souvenir()
                {
                    Name = "Wooden Box", Description = "This is a Maori Wooden Box", Price = 9, SupplierID = 2, CategoryID = 1, PathOfFile = "/Images/SouvenirImages/M21.jpg"
                },
                new Souvenir()
                {
                    Name = "Wooden Mask", Description = "This is a Maori's unique Wooden Mask", Price = 19, SupplierID = 3, CategoryID = 1, PathOfFile = "/Images/SouvenirImages/M22.jpg"
                },
                new Souvenir()
                {
                    Name = "Mask", Description = "This is Maori Mask", Price = 29, SupplierID = 4, CategoryID = 1, PathOfFile = "/Images/SouvenirImages/M23.jpg"
                },
                new Souvenir()
                {
                    Name = "Wooden Totem2", Description = "This is anther Maori's unique Maori wooden totem", Price = 79, SupplierID = 4, CategoryID = 1, PathOfFile = "/Images/SouvenirImages/M04.jpg"
                },
                new Souvenir()
                {
                    Name = "Wool doll", Description = "There are three Wool dolls", Price = 39, SupplierID = 1, CategoryID = 1, PathOfFile = "/Images/SouvenirImages/M05.jpg"
                },
                new Souvenir()
                {
                    Name = "Spiral Jade", Description = "This is a Spiral Jade pendant", Price = 249, SupplierID = 2, CategoryID = 1, PathOfFile = "/Images/SouvenirImages/M06.jpg"
                },
                new Souvenir()
                {
                    Name = "Spiral Ring", Description = "This is a silver Spiral Ring", Price = 69, SupplierID = 3, CategoryID = 1, PathOfFile = "/Images/SouvenirImages/M07.jpg"
                },
                new Souvenir()
                {
                    Name = "Maori Woman", Description = "This is a picture of a Maori Women", Price = 239, SupplierID = 4, CategoryID = 1, PathOfFile = "/Images/SouvenirImages/M08.jpg"
                },
                new Souvenir()
                {
                    Name = "Opera Doll", Description = "This is a Opera Doll", Price = 48, SupplierID = 3, CategoryID = 2, PathOfFile = "/Images/SouvenirImages/C35.jpg"
                },
                new Souvenir()
                {
                    Name = "Silver Face", Description = "This is a Silver Face pendant", Price = 89, SupplierID = 2, CategoryID = 1, PathOfFile = "/Images/SouvenirImages/M10.jpg"
                },
                new Souvenir()
                {
                    Name = "Spiral Pendant", Description = "This is a colorful Spiral pendant", Price = 279, SupplierID = 3, CategoryID = 1, PathOfFile = "/Images/SouvenirImages/M11.jpg"
                },

                new Souvenir()
                {
                    Name = "Red Jade", Description = "This is a Red Spiral Jade pendant", Price = 99, SupplierID = 1, CategoryID = 1, PathOfFile = "/Images/SouvenirImages/M13.jpg"
                },


                new Souvenir()
                {
                    Name = "Paper Bridge", Description = "This is a Paper Bridge", Price = 58, SupplierID = 3, CategoryID = 2, PathOfFile = "/Images/SouvenirImages/C02.jpg"
                },



                new Souvenir()
                {
                    Name = "Wooden Moer", Description = "This is a Wooden Moer for smoke", Price = 38, SupplierID = 3, CategoryID = 2, PathOfFile = "/Images/SouvenirImages/C06.jpg"
                },
                new Souvenir()
                {
                    Name = "Bronze Soldier", Description = "There are two Bronze Soldiers", Price = 498, SupplierID = 4, CategoryID = 2, PathOfFile = "/Images/SouvenirImages/C07.jpg"
                },
                new Souvenir()
                {
                    Name = "Blossom Fan", Description = "This is a Blossom Fan", Price = 68, SupplierID = 1, CategoryID = 2, PathOfFile = "/Images/SouvenirImages/C08.jpg"
                },
                new Souvenir()
                {
                    Name = "Porcelain Bowl", Description = "This is expensive Porcelain Bowl", Price = 1999, SupplierID = 2, CategoryID = 2, PathOfFile = "/Images/SouvenirImages/C09.jpg"
                },
                new Souvenir()
                {
                    Name = "Wooden Chess", Description = "This is a Wooden Chess", Price = 198, SupplierID = 3, CategoryID = 2, PathOfFile = "/Images/SouvenirImages/C10.jpg"
                },
                new Souvenir()
                {
                    Name = "Silk Fan", Description = "This is a Silk Fan", Price = 98, SupplierID = 4, CategoryID = 2, PathOfFile = "/Images/SouvenirImages/C11.jpg"
                },
                new Souvenir()
                {
                    Name = "Pearl Necklace", Description = "This is a real Pearl Necklace", Price = 298, SupplierID = 2, CategoryID = 2, PathOfFile = "/Images/SouvenirImages/C12.jpg"
                },
                new Souvenir()
                {
                    Name = "Wooden Book", Description = "This is a silver wooden book", Price = 49, SupplierID = 4, CategoryID = 1, PathOfFile = "/Images/SouvenirImages/M12.jpg"
                },
                new Souvenir()
                {
                    Name = "Egyptian Cat", Description = "This is a Egyptian Cat", Price = 198, SupplierID = 4, CategoryID = 3, PathOfFile = "/Images/SouvenirImages/E12.jpg"
                },
                new Souvenir()
                {
                    Name = "Chinese Doll", Description = "This is a Chinese Doll", Price = 38, SupplierID = 2, CategoryID = 2, PathOfFile = "/Images/SouvenirImages/C14.jpg"
                },
                new Souvenir()
                {
                    Name = "Sand Bag", Description = "This is a Sand Bag", Price = 79, SupplierID = 2, CategoryID = 3, PathOfFile = "/Images/SouvenirImages/E01.jpg"
                },
                new Souvenir()
                {
                    Name = "Bronze Pot", Description = "This is a Bronze Pot", Price = 69, SupplierID = 3, CategoryID = 3, PathOfFile = "/Images/SouvenirImages/E02.jpg"
                },
                new Souvenir()
                {
                    Name = "Bronze Sphinx", Description = "This is a Bronze Sphinx", Price = 399, SupplierID = 2, CategoryID = 3, PathOfFile = "/Images/SouvenirImages/E03.jpg"
                },
                new Souvenir()
                {
                    Name = "Eye Ring", Description = "This is a silver Eye Ring", Price = 49, SupplierID = 1, CategoryID = 3, PathOfFile = "/Images/SouvenirImages/E04.jpg"
                },
                new Souvenir()
                {
                    Name = "Silver Azir", Description = "This is a Silver Azir who is the king of sand", Price = 399, SupplierID = 4, CategoryID = 3, PathOfFile = "/Images/SouvenirImages/E05.jpg"
                },
                new Souvenir()
                {
                    Name = "Wooden Jade", Description = "This is a Wooden Jade pendant", Price = 99, SupplierID = 1, CategoryID = 1, PathOfFile = "/Images/SouvenirImages/M16.jpg"
                },
                new Souvenir()
                {
                    Name = "Pyramid", Description = "This is a magical Pyramid", Price = 1399, SupplierID = 2, CategoryID = 3, PathOfFile = "/Images/SouvenirImages/E06.jpg"
                },
                new Souvenir()
                {
                    Name = "Chopsticks", Description = "There are two pairs of Chopsticks", Price = 48, SupplierID = 2, CategoryID = 2, PathOfFile = "/Images/SouvenirImages/C01.jpg"
                },
                new Souvenir()
                {
                    Name = "Egyptian Cat", Description = "This is a pair Egyptian Cats", Price = 399, SupplierID = 2, CategoryID = 3, PathOfFile = "/Images/SouvenirImages/E07.jpg"
                },
                new Souvenir()
                {
                    Name = "Bronze Elephant", Description = "This is a Bronze Elephant", Price = 299, SupplierID = 2, CategoryID = 4, PathOfFile = "/Images/SouvenirImages/I01.jpg"
                },
                new Souvenir()
                {
                    Name = "Bronze Tower", Description = "This is a Bronze Tower", Price = 199, SupplierID = 1, CategoryID = 4, PathOfFile = "/Images/SouvenirImages/I02.jpg"
                },
                new Souvenir()
                {
                    Name = "Wooden Pot", Description = "This is a Wooden Pot", Price = 39, SupplierID = 3, CategoryID = 4, PathOfFile = "/Images/SouvenirImages/I03.jpg"
                },
                new Souvenir()
                {
                    Name = "Dragon Jade", Description = "This is a Dragon Jade pendant", Price = 898, SupplierID = 1, CategoryID = 2, PathOfFile = "/Images/SouvenirImages/C04.jpg"
                },
                new Souvenir()
                {
                    Name = "Wooden Box", Description = "This is a Wooden Box", Price = 89, SupplierID = 4, CategoryID = 4, PathOfFile = "/Images/SouvenirImages/I12.jpg"
                },
                new Souvenir()
                {
                    Name = "China Doll", Description = "This is a China Doll", Price = 78, SupplierID = 2, CategoryID = 2, PathOfFile = "/Images/SouvenirImages/C34.jpg"
                },
                new Souvenir()
                {
                    Name = "Butterfly", Description = "This is a butterfly", Price = 148, SupplierID = 3, CategoryID = 4, PathOfFile = "/Images/SouvenirImages/E32.jpg"
                },
                new Souvenir()
                {
                    Name = "Song China", Description = "This is a Song China", Price = 1498, SupplierID = 4, CategoryID = 2, PathOfFile = "/Images/SouvenirImages/C33.jpg"
                },



                new Souvenir()
                {
                    Name = "Roma Helmet", Description = "This is a Roma Helmet", Price = 79, SupplierID = 3, CategoryID = 5, PathOfFile = "/Images/SouvenirImages/L31.jpg"
                },
                new Souvenir()
                {
                    Name = "Silver House", Description = "This is a silver house", Price = 29, SupplierID = 5, CategoryID = 5, PathOfFile = "/Images/SouvenirImages/L32.jpg"
                },

                new Souvenir()
                {
                    Name = "Stone Woman", Description = "This is a Stone Woman", Price = 256, SupplierID = 3, CategoryID = 5, PathOfFile = "/Images/SouvenirImages/L35.jpg"
                },
                new Souvenir()
                {
                    Name = "Crystal Heart", Description = "This is a Crystal Heart", Price = 22, SupplierID = 5, CategoryID = 5, PathOfFile = "/Images/SouvenirImages/L38.jpg"
                }
            };

            foreach (var item in souvenirs)
            {
                context.Souvenirs.Add(item);
            }
            context.SaveChanges();
        }
コード例 #27
0
        public ActionResult Edit(RequestEditView model, int id)
        {
            Boolean isValid = true;

            ViewBag.ErrorMessageSouvenirName = null;
            ViewBag.ErrorMessageCountry      = null;
            ViewBag.ErrorMessageAmount       = null;
            ViewBag.ErrorMessagePrice        = null;
            ViewBag.ErrorMessageCurrency     = null;
            ViewBag.ErrorMessageDescription  = null;
            ViewBag.ErrorMessageStatus       = null;


            if (model.souvenirName == null || model.souvenirName.Length < 3 || model.souvenirName.Length > 30)
            {
                ViewBag.ErrorMessageSouvenirName = "The name of your souvenir should have between 3 and 30 characters.";
                isValid = false;
            }
            if (model.countrySouv == null)
            {
                ViewBag.ErrorMessageCountry = "Please select a country.";
                isValid = false;
            }
            if (model.amount < 1 || model.amount > 1000)
            {
                ViewBag.ErrorMessageAmount = "Please enter a quantity between 1 and 1000.";
                isValid = false;
            }
            string tmp = model.price.Replace(",", "");

            tmp = tmp.Replace(".", "");
            if (model.price == null || model.price.Length > 10)
            {
                ViewBag.ErrorMessagePrice = "Please enter a price under 10 digits.";
                isValid = false;
            }
            if ((model.price.Length - tmp.Length) > 1)
            {
                ViewBag.ErrorMessagePrice = "Maximum one ',' or '.' !";
                isValid = false;
            }
            if (model.currency == null)
            {
                ViewBag.ErrorMessageCurrency = "Please select a currency.";
                isValid = false;
            }
            if (model.descriptionSouv == null || model.descriptionSouv.Length > 300 || model.descriptionSouv.Length < 5)
            {
                ViewBag.ErrorMessageDescription = "Please enter a description of your souvenir, it should be more than 5 and less than 300 characters.";
                isValid = false;
            }
            if (model.status == null)
            {
                ViewBag.ErrorMessageStatus = "Please select a status.";
                isValid = false;
            }

            if (isValid == true)
            {
                SouvenirInfo souvenirInfo = db.souvenirInfos.Find(souvenirID_tmp);
                if (model.price.Contains(","))
                {
                    model.price = model.price.Replace(",", ".");
                }
                NumberStyles style   = NumberStyles.AllowDecimalPoint;
                CultureInfo  culture = CultureInfo.CreateSpecificCulture("en-US");
                double       d;
                double.TryParse(model.price, style, culture, out d);
                souvenirInfo.price           = Math.Round(d, 2);
                souvenirInfo.currency        = model.currency;
                souvenirInfo.descriptionSouv = model.descriptionSouv;
                db.Entry(souvenirInfo).CurrentValues.SetValues(souvenirInfo);
                db.SaveChanges();

                Souvenir souvenir = db.souvenirs.Find(souvenirID_tmp);
                souvenir.souvenirName = model.souvenirName;
                souvenir.countrySouv  = model.countrySouv;
                db.Entry(souvenir).CurrentValues.SetValues(souvenir);
                db.SaveChanges();

                Request request = db.requests.Find(souvenirID_tmp);
                request.amount = model.amount;
                request.status = model.status;
                request.reward = (double)(request.amount * request.souvenir.souvenirInfo.price * rewardpercent) / 100;
                request.reward = Math.Round(request.reward, 2);
                db.Entry(request).CurrentValues.SetValues(request);
                db.SaveChanges();

                souvenirID_tmp = null;
                return(RedirectToAction("MyOwnRequests"));
            }
            else
            {
                return(View("Edit", model));
            }
        }
コード例 #28
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name,Price,Description,SupplierID,CategoryID,Image")] Souvenir souvenir, IFormFile _files)
        {
            var relativeName = "";
            var fileName     = "";

            if (_files != null && _files.Length > 0)
            {
                fileName = ContentDispositionHeaderValue
                           .Parse(_files.ContentDisposition)
                           .FileName
                           .Trim('"');
                //Path for localhost
                relativeName = "/images/products/" + DateTime.Now.ToString("ddMMyyyy-HHmmssffffff") + fileName;

                using (FileStream fs = System.IO.File.Create(_hostingEnv.WebRootPath + relativeName))
                {
                    await _files.CopyToAsync(fs);

                    fs.Flush();
                }
            }
            else
            {
                var so = await _context.Souvenirs
                         .AsNoTracking()
                         .SingleOrDefaultAsync(s => s.ID == id);

                relativeName = so.Image;
            }
            souvenir.Image = relativeName;

            if (id != souvenir.ID)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(souvenir);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SouvenirExists(souvenir.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            //var souvenirToUpdate = await _context.Souvenirs.SingleOrDefaultAsync(s => s.ID == id);
            //if (await TryUpdateModelAsync<Souvenir>(
            //    souvenirToUpdate,
            //    "",
            //    s => s.Name, s => s.Price, s => s.Description, s => s.SupplierID, s => s.CategoryID, s => s.Image))
            //{
            //    try
            //    {
            //        _context.Update(souvenir);
            //        await _context.SaveChangesAsync();
            //        return RedirectToAction(nameof(Index));
            //    }
            //    catch (DbUpdateException /* ex */)
            //    {
            //        ModelState.AddModelError("", "Unable to save changes." + "Try again, and if the problem persists " + "see your system administrator");
            //    }
            //}
            ViewData["CategoryID"] = new SelectList(_context.Categories, "ID", "Name", souvenir.CategoryID);
            ViewData["SupplierID"] = new SelectList(_context.Suppliers, "ID", "Name", souvenir.SupplierID);
            return(View(souvenir));
        }
コード例 #29
0
        public static void Initialize(ApplicationDbContext context)
        {
            context.Database.EnsureCreated();

            // Look for any categorys.
            if (context.Suppliers.Any())
            {
                return;   // DB has been seeded
            }

            var categorys = new Category[]
            {
                new Category {
                    Name = "Maori Gifts"
                },
                new Category {
                    Name = "Mugs"
                },
                new Category {
                    Name = "T-Shirts"
                },
                new Category {
                    Name = "Hats"
                }
            };

            foreach (Category c in categorys)
            {
                context.Categorys.Add(c);
            }
            context.SaveChanges();

            var suppliers = new Supplier[]
            {
                new Supplier {
                    Name = "Maori Local", Email = "*****@*****.**", ContactPerson = "Dahi Morle", Phone = "0212523355", Address = "99 Queens Road, Lower Hut, Wellington, New Zealand"
                },
                new Supplier {
                    Name = "Natural Goods", Email = "*****@*****.**", ContactPerson = "Eric White", Phone = "0212511189", Address = "1239 New North Road, Avondale, Auckland, New Zealand"
                }
            };

            foreach (Supplier s in suppliers)
            {
                context.Suppliers.Add(s);
            }
            context.SaveChanges();

            var souvenirs = new Souvenir[]
            {
                //gifts
                new Souvenir {
                    Name = "Cotton Scarf", Description = "100% Cotton, natural non-allergic and soft fabric.You can style this HANDMADE neck scarf as SHAWL, WRAP, as INFINITY scarf or tie around your head. Looks great with tops, dresses, jackets, coats, casual or business outfit.", Price = 65.99, PathOfImage = "gift001.png", CategoryName = "Maori Gifts", SupplierName = "Maori Local"
                },
                new Souvenir {
                    Name = "Silk Scarf", Description = "Great as a shawl, head wrap, hijab, stole or light scarves for women. Wrap this pashmina scarf around your shoulder will warm you body in a evening night. And this silk scarf pashminas will dress up any outfit in any occasion. Such as: warm shawls and wraps for evening dresses or wedding warm shawl.", Price = 35.99, PathOfImage = "gift002.png", CategoryName = "Maori Gifts", SupplierName = "Maori Local"
                },
                new Souvenir {
                    Name = "Wool Scarf", Description = "100% fine wool from Australia, bringing excellent warm feeling without making you feel heavy.Perfect for matching any dress and suitable for daily life, shopping, travelling, wedding, party, ceremonies and any important events.", Price = 75.99, PathOfImage = "gift003.png", CategoryName = "Maori Gifts", SupplierName = "Maori Local"
                },
                new Souvenir {
                    Name = "Blanket", Description = "100% polar fleece blanket - high quality collection of luxury and cozy polar fleece fabric.Lightweight, ultra-soft, warm, and durable blanket. Classic luxuriously looking plaid pattern design in variety of colors. Perfect gift for friends & family for household, camping, &other usages.", Price = 55.99, PathOfImage = "gift004.png", CategoryName = "Maori Gifts", SupplierName = "Maori Local"
                },
                new Souvenir {
                    Name = "Toy", Description = "Embroidered eye and nose details ensure safe use for all ages. Machine-washable. Ages 0+.", Price = 15.99, PathOfImage = "gift005.png", CategoryName = "Maori Gifts", SupplierName = "Maori Local"
                },
                new Souvenir {
                    Name = "Blanket", Description = "100% polar fleece blanket - high quality collection of luxury and cozy polar fleece fabric.", Price = 45.99, PathOfImage = "gift006.png", CategoryName = "Maori Gifts", SupplierName = "Maori Local"
                },
                new Souvenir {
                    Name = "Green Plants", Description = "Incredibly detailed characteristics - these succulents look and feel real. Extremely colorful and lifelike. Great for home and office, wreaths, bouquets, gifts, and other arrangments.", Price = 4.99, PathOfImage = "gift007.png", CategoryName = "Maori Gifts", SupplierName = "Maori Local"
                },
                new Souvenir {
                    Name = "Bear Toy", Description = "Embroidered eye and nose details ensure safe use for all ages. Machine-washable. ", Price = 15.99, PathOfImage = "gift008.png", CategoryName = "Maori Gifts", SupplierName = "Maori Local"
                },
                new Souvenir {
                    Name = "Letter Toys", Description = "Incredibly detailed characteristics", Price = 6.99, PathOfImage = "gift009.png", CategoryName = "Maori Gifts", SupplierName = "Maori Local"
                },
                new Souvenir {
                    Name = "Carrot Toys", Description = "Incredibly detailed characteristics", Price = 7.99, PathOfImage = "gift010.png", CategoryName = "Maori Gifts", SupplierName = "Maori Local"
                },
                new Souvenir {
                    Name = "Doggy Toy", Description = "Incredibly detailed characteristics. Machine-washable.", Price = 11.99, PathOfImage = "gift011.png", CategoryName = "Maori Gifts", SupplierName = "Maori Local"
                },
                new Souvenir {
                    Name = "Bear Toy", Description = "100% fine wool from Australia, bringing excellent warm feeling without making you feel heavy.", Price = 10.99, PathOfImage = "gift012.png", CategoryName = "Maori Gifts", SupplierName = "Maori Local"
                },
                new Souvenir {
                    Name = "Wool Scarf", Description = "100% fine wool from Australia, bringing excellent warm feeling without making you feel heavy.", Price = 37.99, PathOfImage = "gift013.png", CategoryName = "Maori Gifts", SupplierName = "Maori Local"
                },
                new Souvenir {
                    Name = "Kiwibird Sculpture", Description = "Stretched Canvas ready to be put on the wall. Satisfaction Guarantee 100%. Brighten your home of Office with the art prints from our store.", Price = 19.99, PathOfImage = "gift014.png", CategoryName = "Maori Gifts", SupplierName = "Maori Local"
                },
                new Souvenir {
                    Name = "All Black Toy", Description = "Bring New Zealand to your home. Best souvenir ever.", Price = 25.99, PathOfImage = "gift015.png", CategoryName = "Maori Gifts", SupplierName = "Maori Local"
                },
                new Souvenir {
                    Name = "Kiwibird Toy", Description = "Stretched Canvas ready to be put on the wall. Satisfaction Guarantee 100%.", Price = 12.99, PathOfImage = "gift016.png", CategoryName = "Maori Gifts", SupplierName = "Maori Local"
                },
                new Souvenir {
                    Name = "All Black Toy", Description = "Bring New Zealand to your home. Best souvenir ever.", Price = 25.99, PathOfImage = "gift017.png", CategoryName = "Maori Gifts", SupplierName = "Maori Local"
                },
                new Souvenir {
                    Name = "All Black Board", Description = "Bring New Zealand to your home. Best souvenir ever.", Price = 22.99, PathOfImage = "gift018.png", CategoryName = "Maori Gifts", SupplierName = "Maori Local"
                },
                new Souvenir {
                    Name = "Pillow Cover", Description = "All fabric edges are sewn with zigzag overlock stitch to prevent fray and ensure durability.", Price = 36.99, PathOfImage = "gift019.png", CategoryName = "Maori Gifts", SupplierName = "Maori Local"
                },
                new Souvenir {
                    Name = "Art Pillow Cover", Description = " Soft, Textured, made with color matching invisible zipper and allows easy insertion and removal of pillow inserts.", Price = 31.99, PathOfImage = "gift020.png", CategoryName = "Maori Gifts", SupplierName = "Maori Local"
                },
                new Souvenir {
                    Name = "Mari Jade", Description = "Green Aventurine Jade Helps with sexual imbalances and grief caused by sexual abuse", Price = 55.99, PathOfImage = "gift021.png", CategoryName = "Maori Gifts", SupplierName = "Maori Local"
                },
                new Souvenir {
                    Name = "Mari Bag", Description = "This is the perfect market tote you can use. You can carry from your groceries to your study books. Use the tote as a beach bag too! Our Style in Print designs are the perfect combination to personalize your totes.", Price = 65.99, PathOfImage = "gift022.png", CategoryName = "Maori Gifts", SupplierName = "Maori Local"
                },
                new Souvenir {
                    Name = "Mari Sculpture", Description = "Incredibly detailed characteristics.", Price = 75.99, PathOfImage = "gift023.png", CategoryName = "Maori Gifts", SupplierName = "Maori Local"
                },
                new Souvenir {
                    Name = "Mari Sculpture", Description = "Incredibly detailed characteristics.", Price = 65.99, PathOfImage = "gift024.png", CategoryName = "Maori Gifts", SupplierName = "Maori Local"
                },
                new Souvenir {
                    Name = "Jade Necklace", Description = "Green Aventurine Jade Helps with sexual imbalances and grief caused by sexual abuse", Price = 25.99, PathOfImage = "gift025.png", CategoryName = "Maori Gifts", SupplierName = "Maori Local"
                },
                new Souvenir {
                    Name = "Mari Jade", Description = "Green Aventurine Jade Helps with sexual imbalances and grief caused by sexual abuse", Price = 35.99, PathOfImage = "gift026.png", CategoryName = "Maori Gifts", SupplierName = "Maori Local"
                },
                new Souvenir {
                    Name = "Kiwi Lighter", Description = "Bring New Zealand to your home. Best souvenir ever.", Price = 29.99, PathOfImage = "gift027.png", CategoryName = "Maori Gifts", SupplierName = "Maori Local"
                },
                new Souvenir {
                    Name = "Kiwi Toy", Description = "Bring New Zealand to your home. Best souvenir ever.", Price = 15.99, PathOfImage = "gift028.png", CategoryName = "Maori Gifts", SupplierName = "Maori Local"
                },
                new Souvenir {
                    Name = "Jade Bracelet", Description = "This Amber Bracelet is made on Elastic Band so it can slightly adjust in size.  This bracelet is packed together with a pouch so it can be a great gift for any occasion.", Price = 35.99, PathOfImage = "gift029.png", CategoryName = "Maori Gifts", SupplierName = "Maori Local"
                },
                new Souvenir {
                    Name = "Jade Bracelet", Description = "This Amber Bracelet is made on Elastic Band so it can slightly adjust in size.  This bracelet is packed together with a pouch so it can be a great gift for any occasion.", Price = 39.99, PathOfImage = "gift030.png", CategoryName = "Maori Gifts", SupplierName = "Maori Local"
                },
                //Hats
                new Souvenir {
                    Name = "Doggy Hat", Description = "Yellow wool doggy hat, best gift for your little doggy.", Price = 0.00, PathOfImage = "hat001.png", CategoryName = "Hats", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "White Hat", Description = "White beautiful hat for travel.", Price = 7.99, PathOfImage = "hat002.png", CategoryName = "Hats", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "Brown Hat", Description = "hat on sale", Price = 9.99, PathOfImage = "hat003.png", CategoryName = "Hats", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "Red Hat", Description = "hat on sale", Price = 15.99, PathOfImage = "hat004.png", CategoryName = "Hats", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "Travel Hat", Description = "hat on sale", Price = 11.99, PathOfImage = "hat005.png", CategoryName = "Hats", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "Green Hat", Description = "hat on sale", Price = 12.99, PathOfImage = "hat006.png", CategoryName = "Hats", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "Green Hat", Description = "hat on sale", Price = 8.99, PathOfImage = "hat007.png", CategoryName = "Hats", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "Catty Hat", Description = "Not On sale", Price = 0.00, PathOfImage = "hat008.png", CategoryName = "Hats", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "Kids Hat", Description = "hat on sale", Price = 8.99, PathOfImage = "hat009.png", CategoryName = "Hats", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "Mil Hat", Description = "hat on sale", Price = 9.99, PathOfImage = "hat010.png", CategoryName = "Hats", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "Love Hat", Description = "hat on sale", Price = 11.99, PathOfImage = "hat011.png", CategoryName = "Hats", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "Trip Hat", Description = "hat on sale", Price = 15.99, PathOfImage = "hat012.png", CategoryName = "Hats", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "Lady Hat", Description = "hat on sale", Price = 18.99, PathOfImage = "hat013.png", CategoryName = "Hats", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "Sun Hat", Description = "hat on sale", Price = 8.99, PathOfImage = "hat014.png", CategoryName = "Hats", SupplierName = "Natural Goods"
                },

                //MuSouvenir
                new Souvenir {
                    Name = "Coffe Cup", Description = "Cup on Sale", Price = 5.99, PathOfImage = "cup001.png", CategoryName = "Mugs", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "White Cup", Description = "Cup on Sale", Price = 6.99, PathOfImage = "cup002.png", CategoryName = "Mugs", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "Lady Cup", Description = "Cup on Sale", Price = 6.99, PathOfImage = "cup003.png", CategoryName = "Mugs", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "Coffe Cup", Description = "Cup on Sale", Price = 5.99, PathOfImage = "cup004.png", CategoryName = "Mugs", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "Coffe Cup", Description = "Cup on Sale", Price = 4.99, PathOfImage = "cup005.png", CategoryName = "Mugs", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "Coffe Cups", Description = "Cup on Sale", Price = 12.99, PathOfImage = "cup006.png", CategoryName = "Mugs", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "Tea Cup", Description = "Cup on Sale", Price = 7.99, PathOfImage = "cup007.png", CategoryName = "Mugs", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "White Cup", Description = "Cup on Sale", Price = 8.99, PathOfImage = "cup008.png", CategoryName = "Mugs", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "White Cup", Description = "Cup on Sale", Price = 6.99, PathOfImage = "cup009.png", CategoryName = "Mugs", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "Gray Cup", Description = "Cup on Sale", Price = 8.99, PathOfImage = "cup010.png", CategoryName = "Mugs", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "Mug", Description = "Cup on Sale", Price = 7.99, PathOfImage = "cup011.png", CategoryName = "Mugs", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "White Mug", Description = "Cup on Sale", Price = 9.99, PathOfImage = "cup012.png", CategoryName = "Mugs", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "White Mug", Description = "Cup on Sale", Price = 8.99, PathOfImage = "cup013.png", CategoryName = "Mugs", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "Blue cup", Description = "Cup on Sale", Price = 6.99, PathOfImage = "cup014.png", CategoryName = "Mugs", SupplierName = "Natural Goods"
                },

                //T-Souvenir
                new Souvenir {
                    Name = "Man's Color", Description = "On Sale", Price = 24.99, PathOfImage = "t-shirt001.png", CategoryName = "T-Shirts", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "T-Shirt Man", Description = "On Sale", Price = 24.99, PathOfImage = "t-shirt002.png", CategoryName = "T-Shirts", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "T-Shirt Woman", Description = "On Sale", Price = 24.99, PathOfImage = "t-shirt003.png", CategoryName = "T-Shirts", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "T-Shirt Man", Description = "On Sale", Price = 24.99, PathOfImage = "t-shirt004.png", CategoryName = "T-Shirts", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "T-Shirt Woman", Description = "On Sale", Price = 24.99, PathOfImage = "t-shirt005.png", CategoryName = "T-Shirts", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "T-Shirt Woman", Description = "On Sale", Price = 24.99, PathOfImage = "t-shirt006.png", CategoryName = "T-Shirts", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "T-Shirt Man", Description = "On Sale", Price = 24.99, PathOfImage = "t-shirt007.png", CategoryName = "T-Shirts", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "T-Shirt Man", Description = "On Sale", Price = 24.99, PathOfImage = "t-shirt008.png", CategoryName = "T-Shirts", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "T-Shirt Doddy", Description = "Not On Sale", Price = 0.00, PathOfImage = "t-shirt009.png", CategoryName = "T-Shirts", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "T-Shirt Man", Description = "On Sale", Price = 24.99, PathOfImage = "t-shirt010.png", CategoryName = "T-Shirts", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "all Black", Description = "On Sale", Price = 34.99, PathOfImage = "t-shirt011.png", CategoryName = "T-Shirts", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "T-Shirt Girl", Description = "On Sale", Price = 18.99, PathOfImage = "t-shirt012.png", CategoryName = "T-Shirts", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "T-Shirt Girl", Description = "On Sale", Price = 18.99, PathOfImage = "t-shirt013.png", CategoryName = "T-Shirts", SupplierName = "Natural Goods"
                },
                new Souvenir {
                    Name = "T-Shirt Man", Description = "On Sale", Price = 24.99, PathOfImage = "t-shirt014.png", CategoryName = "T-Shirts", SupplierName = "Natural Goods"
                }
            };

            foreach (Souvenir p in souvenirs)
            {
                context.Souvenirs.Add(p);
            }
            context.SaveChanges();
        }
コード例 #30
0
        public ActionResult Create(RequestCreate model, HttpPostedFileBase file)
        {
            Boolean isValid = true;

            ViewBag.ErrorMessageSouvenirName = null;
            ViewBag.ErrorMessageCountry      = null;
            ViewBag.ErrorMessageAmount       = null;
            ViewBag.ErrorMessagePrice        = null;
            ViewBag.ErrorMessageCurrency     = null;
            ViewBag.ErrorMessageDescription  = null;

            if (model.souvenirName == null || model.souvenirName.Length < 3 || model.souvenirName.Length > 30)
            {
                ViewBag.ErrorMessageSouvenirName = "The name of your souvenir should have between 3 and 30 characters.";
                isValid = false;
            }
            if (model.countrySouv == null)
            {
                ViewBag.ErrorMessageCountry = "Please select a country.";
                isValid = false;
            }
            //Fehlermeldung von amount wird noch nicht angezeigt
            if (model.amount < 1 || model.amount > 1000)
            {
                ViewBag.ErrorMessageAmount = "Please enter a quantity between 1 and 1000.";
                isValid = false;
            }
            if (model.price == null)
            {
                ViewBag.ErrorMessagePrice = "Please enter a price";
                isValid = false;
            }
            else
            {
                string tmp = model.price.Replace(",", "");
                tmp = tmp.Replace(".", "");
                if (model.price == null || model.price.Length > 10)
                {
                    ViewBag.ErrorMessagePrice = "Please enter a price under 10 digits.";
                    isValid = false;
                }
                if ((model.price.Length - tmp.Length) > 1)
                {
                    ViewBag.ErrorMessagePrice = "Maximum one ',' or '.' !";
                    isValid = false;
                }
            }
            if (model.currency == null)
            {
                ViewBag.ErrorMessageCurrency = "Please select a currency.";
                isValid = false;
            }
            if (model.descriptionSouv == null || model.descriptionSouv.Length > 300 || model.descriptionSouv.Length < 5)
            {
                ViewBag.ErrorMessageDescription = "Please enter a description of your souvenir, it should be more than 5 and less than 300 characters.";
                isValid = false;
            }

            if (isValid == true)
            {
                SouvenirInfo souvenirInfo = new SouvenirInfo();
                if (model.price.Contains(","))
                {
                    model.price = model.price.Replace(",", ".");
                }
                NumberStyles style   = NumberStyles.AllowDecimalPoint;
                CultureInfo  culture = CultureInfo.CreateSpecificCulture("en-US");
                double       d;
                double.TryParse(model.price, style, culture, out d);
                souvenirInfo.price           = Math.Round(d, 2);
                souvenirInfo.currency        = model.currency;
                souvenirInfo.descriptionSouv = model.descriptionSouv;


                db.souvenirInfos.Add(souvenirInfo);
                db.SaveChanges();

                Souvenir souvenir = new Souvenir();

                try
                {
                    string fileName  = souvenirInfo.souvenirInfoID.ToString();
                    string extension = Path.GetExtension(file.FileName);
                    fileName += extension;
                    souvenir.selectedPictureSouvenir = "~/Content/" + fileName;
                    fileName = Path.Combine(Server.MapPath("~/Content/"), fileName);
                    file.SaveAs(fileName);
                }
                catch (Exception)
                {
                    souvenir.selectedPictureSouvenir = "~/Content/defaultSouvenir.png";
                }
                souvenir.souvenirID   = souvenirInfo.souvenirInfoID;
                souvenir.souvenirName = model.souvenirName;
                souvenir.countrySouv  = model.countrySouv;
                souvenir.souvenirInfo = souvenirInfo;

                db.souvenirs.Add(souvenir);
                db.SaveChanges();

                Customer customer = db.customers.Find(Session["userName"]);

                Request request = new Request();
                request.souvenir  = souvenir;
                request.customer  = customer;
                request.amount    = model.amount;
                request.reward    = (double)(request.amount * request.souvenir.souvenirInfo.price * rewardpercent) / 100;
                request.reward    = Math.Round(request.reward, 2);
                request.status    = "new";
                request.requestID = souvenirInfo.souvenirInfoID;

                db.requests.Add(request);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            else
            {
                return(View("Create", model));
            }
        }