public ActionResult Create(Merchant merchant, string command)
        {
            if(ModelState.IsValid)
            {
                //assigning default values
                merchant.super_user = 0;
                merchant.created = DateTime.Now;
                merchant.status = 1;
                merchant.is_synched = 1;

                using(Context db = new Context())
                {
                    db.Merchants.Add(merchant);
                    db.SaveChanges();
                }

                if(command == "2")//send email
                {
                    string body = "Hi <b>" + merchant.merchant_name + "</b>,<br/>" + "Your account is successfully created with UserName - <b>"+ merchant.username + "</b>, password - " + " <b>" + merchant.password + "</b>.<br/> Thanks and Regards <br> Admin.";

                    string subject = "New Account is created for Stylistics.";
                    string appDataPath = Server.MapPath("~/app_data");
                    teamwork.Utility.Mailer.SendMail(subject, body, merchant.contact_email, appDataPath);
                }

                TempData["Status"] = "1";
            }
            return View();
        }
 public ActionResult Details()
 {
     using(Context db = new Context())
     {
         var merchantList = db.Merchants.ToList();
         return View(merchantList);
     }
 }
Esempio n. 3
0
 public ActionResult Index()
 {
     using (Context db = new Context())
     {
         var tags = db.Tags.ToList();
         return View(tags);
     }
 }
 public ActionResult Index()
 {
     using(Context db = new Context())
     {
         var brands = db.Brands.ToList();
         return View(brands);
     }
 }
 public ActionResult Delete(int id)
 {
     using (Context db = new Context())
     {
         var merchant = db.Merchants.Find(id);
         db.Merchants.Remove(merchant);
         db.SaveChanges();
         return RedirectToAction("Details");
     }
 }
 public ActionResult Delete(int id)
 {
     using(Context db = new Context())
     {
         var brand = db.Brands.Find(id);
         db.Brands.Remove(brand);
         db.SaveChanges();
         return RedirectToAction("Index");
     }
 }
 public ActionResult Edit(int id)
 {
     using(Context db = new Context())
     {
         var merchant = db.Merchants.Find(id);
         if (merchant != null)
         {
             return View(merchant);
         }
         else
         {
             return RedirectToAction("Details");
         }
     }
 }
Esempio n. 8
0
        public ActionResult Create(Tag tag)
        {
            if (ModelState.IsValid)
            {
                tag.created = DateTime.Now;
                tag.is_synched = 1;

                using (Context db = new Context())
                {
                    db.Tags.Add(tag);
                    db.SaveChanges();
                    TempData["Status"] = "1";
                    return RedirectToAction("Create");
                }
            }
            return View();
        }
        public ActionResult Create(Brand brand)
        {
            if(ModelState.IsValid)
            {
                brand.created = DateTime.Now;
                brand.is_synched = 1;

                using(Context db = new Context())
                {
                    db.Brands.Add(brand);
                    db.SaveChanges();
                    TempData["Status"] = "1";
                    return RedirectToAction("Create");
                }
            }
            return View();
        }
        // GET: Products
        public ActionResult Add()
        {
            DataAccess.Models.Product product = new DataAccess.Models.Product();

            using (Context db = new Context())
            {
                ViewData["Brands"] =   db.Brands.ToDictionary(i => i.id, i => i.name)
                                       .Select(x =>
                                                    new SelectListItem
                                                    {
                                                        Text = x.Value,
                                                        Value = x.Key.ToString()
                                                    })
                                       .ToList();

            }

            return View(product);
        }
        public ActionResult Add(DataAccess.Models.Product product, string command)
        {
            if(ModelState.IsValid)
            {
                try
                {
                    using (Context context = new DataAccess.Context())
                    {
                        string username = (string)Session["username"];

                        DataAccess.Models.Merchant merchant = context.Merchants.FirstOrDefault(x => x.username == username);

                        product.sizes = product.SizeList.Where(x => x.IsSelected == true).ToList().Sum(s => (int)s.Size);
                        product.colors = product.ColorsList.Where(x => x.IsSelected == true).ToList().Sum(s=>(int)s.Color);
                        product.merchant_id = merchant.id;
                        context.Products.Add(product);
                        context.SaveChanges();

                        if(command == "2")
                        {
                            return RedirectToAction("ProductImage","Products", new { id = product.id, type = Enum.GetName(typeof(DataAccess.Models.ProductType), product.type), category = Enum.GetName(typeof(DataAccess.Models.Category), product.category) });
                        }

                        //confirmation for save done
                        TempData["Status"] = "1";
                    }
                }
                catch (Exception)
                {

                    throw;
                }

            }

            return View(product);
        }
        public ActionResult Edit(int id)
        {
            DataAccess.Models.Product product = new DataAccess.Models.Product();

            using (Context db = new Context())
            {
                ViewData["Brands"] = db.Brands.ToDictionary(i => i.id, i => i.name)
                                       .Select(x =>
                                                    new SelectListItem
                                                    {
                                                        Text = x.Value,
                                                        Value = x.Key.ToString()
                                                    })
                                       .ToList();

                product = db.Products.Find(id);

                //Set Size
                long sizevalue = Convert.ToInt64(product.sizes);
                long[] sizearray = Utility.BitwiseAnd.getFectors(sizevalue);

                foreach (var s in sizearray)
                {
                    DataAccess.Models.enumSize enumsize = (DataAccess.Models.enumSize)s;
                    product.SizeList.ForEach(x =>
                    {
                        if (x.Size.Equals(enumsize))
                        {
                            x.IsSelected = true;
                        }
                    });
                }

                //set color
                long colorvalue = Convert.ToInt64(product.colors);
                long[] colorsarray = Utility.BitwiseAnd.getFectors(colorvalue);

                foreach (var c in colorsarray)
                {
                    DataAccess.Models.enumColor enumcolor = (DataAccess.Models.enumColor)c;
                    product.ColorsList.ForEach(x =>
                    {
                        if (x.Color.Equals(enumcolor))
                        {
                            x.IsSelected = true;
                        }
                    });
                }
            }

            return View(product);
        }
        public ActionResult Edit(Merchant merchant)
        {
            if(ModelState.IsValid)
            {
                using (Context db = new Context())
                {
                    var M = db.Merchants.Find(merchant.id);
                    M = merchant;
                    M.modified = DateTime.Now;
                    TempData["Status"] = "1";

                    return View();

                }
            }
            return View();
        }
 public JsonResult GetProductsByCategory(int category)
 {
     using(Context db = new Context())
     {
         var prod = (from p in db.Products
                     where p.category.Equals(category)
                     select new
                     {
                         p.id,
                         p.name
                     }).ToList();
         return Json(prod);
     }
 }
        //List Product
        public ActionResult Index()
        {
            List<DataAccess.Models.Product> productViewModel = new List<DataAccess.Models.Product>();
            UserType userrole = (UserType)(Convert.ToByte(System.Web.HttpContext.Current.Session["role"]));

            using(Context db = new Context())
            {
                string username = (string)Session["username"];

                DataAccess.Models.Merchant merchant = db.Merchants.FirstOrDefault(x => x.username == username);

                (from p in db.Products
                    join b in db.Brands
                    on p.brand_id equals b.id
                    //where (userrole == UserType.Merchant ? (p.merchant_id == merchant.id) : (1 == 1))
                    select new
                    {
                        p,
                        b.name
                    }).OrderByDescending(x=>x.p.id).ToList()
                    .ForEach(x =>
                    {
                        x.p.BrandName = x.name;
                        productViewModel.Add(x.p);
                    });

                foreach (var item in productViewModel)
                {
                    long value = Convert.ToInt64(item.colors);
                    long[] colors = Utility.BitwiseAnd.getFectors(value);

                    foreach (var c in colors)
                    {
                        DataAccess.Models.enumColor enumcolor = (DataAccess.Models.enumColor)c;
                        item.ColorsList.ForEach(x =>
                        {
                            if(x.Color.Equals(enumcolor))
                            {
                                x.IsSelected = true;
                            }
                        });
                    }
                }

            }

            return View(productViewModel);
        }
        public JsonResult LoadRelatedProduct(int prodId)
        {
            Dictionary<string, object> jsonResult = new Dictionary<string, object>();
            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            using (Context db = new Context())
            {
                var related_Products = (from r in db.Related_Products
                                       join p in db.Products
                                       on r.related_product_id equals p.id
                                       where r.primary_product_id == prodId
                                       select new
                                       {
                                           r.id,
                                           p.name
                                       }).ToList();

                if (related_Products != null)
                {

                    foreach (var item in related_Products)
                    {

                        ViewDataDictionary data = new ViewDataDictionary
                        {
                            new KeyValuePair<string, object>("ProductName", item.name),
                            new KeyValuePair<string, object>("RelatedProductId", item.id)
                        };
                        sb.Append(RenderRazorViewToString("~/Views/Shared/_RelatedProduct.cshtml", data));
                    }
                }
            }
            jsonResult.Add("Html", sb.ToString());
            return Json(jsonResult);
        }
 public JsonResult removeRelatedProduct(int relatedProdMapid)
 {
     using (Context db = new Context())
     {
         Related_Products related_Products = db.Related_Products.Find(relatedProdMapid);
         if(related_Products != null)
         {
             db.Related_Products.Remove(related_Products);
             db.SaveChanges();
             return Json(1);
         }
     }
     return Json(0);
 }
        public ActionResult Edit(DataAccess.Models.Product product)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    using (Context db = new DataAccess.Context())
                    {
                        //var entity = db.Products.Find(product.id);

                        product.sizes = product.SizeList.Where(x => x.IsSelected == true).ToList().Sum(s => (int)s.Size);
                        product.colors = product.ColorsList.Where(x => x.IsSelected == true).ToList().Sum(s => (int)s.Color);
                        product.modified = DateTime.Now;
                        //entity = product;
                        db.Entry(product).State = EntityState.Modified;
                        db.SaveChanges();

                        //confirmation for save done
                        TempData["Status"] = "1";
                    }
                }
                catch (Exception)
                {

                    throw;
                }
            }
            return View(product);
        }
        public JsonResult AddRelatedProduct(int productid, int relatedprodid, string relatedProdName)
        {
            UserType userrole = (UserType)(Convert.ToByte(System.Web.HttpContext.Current.Session["role"]));

            Dictionary<string, object> jsonResult = new Dictionary<string, object>();

            if(userrole == UserType.Merchant)
            {
                string username = (string)Session["username"];
                using(Context db = new Context())
                {
                    Merchant merchant = db.Merchants.FirstOrDefault(x => x.username == username);
                    Related_Products related_Products = new Related_Products();
                    related_Products.merchant_id = merchant.id;
                    related_Products.primary_product_id = productid;
                    related_Products.related_product_id = relatedprodid;
                    related_Products.is_synched = 1;
                    related_Products.created = DateTime.Now;

                    db.Related_Products.Add(related_Products);
                    db.SaveChanges();

                    ViewDataDictionary data = new ViewDataDictionary
                    {
                        new KeyValuePair<string, object>("ProductName", relatedProdName),
                        new KeyValuePair<string, object>("RelatedProductId", related_Products.id)
                    };

                    jsonResult.Add("Html", RenderRazorViewToString("~/Views/Shared/_RelatedProduct.cshtml", data));
                    jsonResult.Add("success",1);
                    return Json(jsonResult, JsonRequestBehavior.AllowGet);
                }

            }
            else if(userrole == UserType.admin)
            {

            }

            jsonResult.Add("success", 0);
            return Json(jsonResult, JsonRequestBehavior.AllowGet);
        }