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 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 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 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();
        }
        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 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 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);
        }
 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);
        }