private PhotoViewModel UploadPhoto(HttpPostedFileBase file, SpecProductViewModel item)
        {
            if (file != null && file.ContentLength < 1 * 1024 * 1024)
            {
                string imageName = Path.GetFileName(file.FileName);
                string physicalPath = Server.MapPath("~/Images/" + imageName);

                //Save the Image in the Images Folder
                file.SaveAs(physicalPath);

                //Save the record in the database
                var photo = new PhotoViewModel()
                {
                    Name = item.ModelNumber,
                    ImageUrl = imageName,
                    PhysicalPath = physicalPath
                };
                db.Photos.Add(photo);
                db.SaveChanges();

                return photo;
            }
            return null;
        }
        public ActionResult ModelCreation(SpecProductViewModel item, HttpPostedFileBase modelPhoto)
        {
            try
            {
                string userId = User.Identity.GetUserId();
                if (userId == null)
                {
                    return RedirectToAction("Login", "Account");
                }

                //Check if the "Supplier" role exists if not it returns a null value
                var role = db.Roles.SingleOrDefault(m => m.Name == "Supplier");

                if (User.IsInRole("Supplier"))
                {
                    var photo = UploadPhoto(modelPhoto, item);
                    if (photo != null)
                    {
                        SpecProductViewModel specProd = Session["SpecProd"] as SpecProductViewModel;
                        int brandId = 0;

                        //This object will allow us to use the convert to ConvertToTitleCase method
                        var helper = new Helper();

                        //Convert to Title Case
                        item.BrandName = helper.ConvertToTitleCase(item.BrandName);

                        //Check if brand name exists
                        var brand = (from b in db.Brands
                                     where b.Name == item.BrandName
                                     select b).FirstOrDefault();

                        //If the brand does not exist create a new one
                        if (brand == null)
                        {
                            var newBrand = new BrandViewModel()
                            {
                                Name = item.BrandName
                            };
                            db.Brands.Add(newBrand);
                            db.SaveChanges();
                            brandId = newBrand.BrandId;
                        }

                        //if the brand does exist assign the existing brandId to the brandId of the new model
                        if (brand != null)
                        {
                            brandId = brand.BrandId;
                        }

                        //Create a new instance of ModelViewModel and assign it to the model variable
                        var model = new ModelViewModel();

                        model.Price = item.Price;
                        model.Status = specProd.Status;
                        model.UserId = userId;
                        model.SupplierId = specProd.SupplierId;
                        model.ItemId = specProd.ItemId;
                        model.BrandId = brandId;
                        model.ModelNumber = item.ModelNumber;
                        model.DtCreated = DateTime.UtcNow;
                        model.NumberDaysToAdvert = item.NumberDaysToAdvert;
                        model.DeliveryInDays = item.DeliveryInDays;

                        //Add a new model to the table model and save changes into the database
                        db.Models.Add(model);
                        db.SaveChanges();

                        var modelCommission = new ModelCommissionViewModel()
                        {
                            ModelId = model.ModelId
                        };
                        string commissionName = "Tier1";
                        if (model.NumberDaysToAdvert >= 1 && model.NumberDaysToAdvert < 6)
                            commissionName = "Tier1";
                        if (model.NumberDaysToAdvert >= 6 && model.NumberDaysToAdvert < 20)
                            commissionName = "Tier2";
                        if (model.NumberDaysToAdvert >= 20)
                            commissionName = "Tier3";

                        int commissionId = (from c in db.Commissions
                                            where c.Name == commissionName
                                            select c.CommissionId).FirstOrDefault();

                        modelCommission.CommissionId = commissionId;

                        db.ModelCommissions.Add(modelCommission);
                        db.SaveChanges();

                        var photoModel = new PhotoModelViewModel()
                        {
                            PhotoId = photo.PhotoId,
                            ModelId = model.ModelId
                        };
                        db.PhotoModels.Add(photoModel);
                        db.SaveChanges();

                        Session["ModelSpecData"] = model;
                        GetSupplierNotification();
                        return RedirectToAction("ModelSpecCreation");

                        //return RedirectToAction("ModelSpecCreation");on("ModelSpecCreation");
                    }
                }
                return RedirectToAction("Login", "Account");
            }
            catch (Exception ex)
            {
                return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString());
            }
        }
        public ActionResult ModelSpecCreation()
        {
            try
            {
                string userId = User.Identity.GetUserId();
                if (userId == null)
                {
                    return RedirectToAction("Login", "Account");
                }

                //Check if the "Supplier" role exists if not it returns a null value
                var role = db.Roles.SingleOrDefault(m => m.Name == "Supplier");

                if (User.IsInRole("Supplier"))
                {
                    ProductViewModel product = Session["Product"] as ProductViewModel;
                    ModelViewModel item = Session["ModelSpecData"] as ModelViewModel;

                    var getSpec = from spec in db.Specifications
                                  join prodSpec in db.ProductSpecs on spec.SpecificationId equals prodSpec.SpecificationId
                                  join prod in db.Products on prodSpec.ProductId equals prod.ProductId
                                  where prod.ProductId == product.ProductId
                                  select spec;

                    var listSpecProduct = new List<SpecProductViewModel>();

                    foreach (var obj in getSpec)
                    {
                        var specProd = new SpecProductViewModel()
                        {
                            ModelNumber = "",
                            BrandName = "",
                            ItemId = item.ItemId,
                            SpecificationId = obj.SpecificationId,
                            SpecDescription = obj.Description,
                            SpecialCatId = obj.SpecialCatId,
                            Value = ""
                        };
                        listSpecProduct.Add(specProd);
                    }
                    GetSupplierNotification();
                    return View(listSpecProduct);
                }
                return RedirectToAction("Login", "Account");
            }
            catch (Exception ex)
            {
                return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString());
            }
        }
        public ActionResult ModelCreation()
        {
            try
            {
                string userId = User.Identity.GetUserId();
                if (userId == null)
                {
                    return RedirectToAction("Login", "Account");
                }

                //Check if the "Supplier" role exists if not it returns a null value
                var role = db.Roles.SingleOrDefault(m => m.Name == "Supplier");

                if (User.IsInRole("Supplier"))
                {
                    ModelViewModel model = TempData["ModelData"] as ModelViewModel;
                    SpecProductViewModel specProd = new SpecProductViewModel()
                    {
                        ItemId = model.ItemId,
                        Price = 0,
                        Status = "Pending",
                        SupplierId = (from s in db.Suppliers
                                      where s.Id == userId
                                      select s.SupplierId).FirstOrDefault(),
                        BrandName = "",
                        UserId = userId,
                        ModelNumber = "",
                        NumberDaysToAdvert = 1,
                        DeliveryInDays = 1
                    };
                    Session["SpecProd"] = specProd;
                    GetSupplierNotification();
                    return View(specProd);

                    //return RedirectToAction("ModelSpecCreation");
                }
                return RedirectToAction("Login", "Account");
            }
            catch (Exception ex)
            {
                return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString());
            }
        }