public ActionResult UpdateStore(StoreModel update)
        {
            //StoreModel update = JsonConvert.DeserializeObject<StoreModel>(obj);
            SIEBUEntities db = new SIEBUEntities();
            Store target_store = db.Stores.FirstOrDefault(s => s.s_id == update.id);

            //if no store is found, create one
            bool add_new = false;
            if (target_store == null)
            {
                add_new = true;
                target_store = new Store();
                target_store.creator_id = WebSecurity.CurrentUserId;
                target_store.created_on = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"));
                target_store.credit = 0;
            }

            //check for conflicting namespace
            if (ValidationController.checkNamespaceAvailability(update.store_namespace) != true)
                return Json(new { error = "The namespace is unavailable for use." }, JsonRequestBehavior.AllowGet);

            target_store.name = update.name;
            target_store.name_space = update.store_namespace;
            target_store.description = update.description;

            target_store.category_id = update.category;
            target_store.status = update.status;

            //create store before connections required
            if (add_new)
            {
                db.Stores.Add(target_store);
                db.SaveChanges();
            }

            if (target_store.logo == null || !(update.logo + "").Contains(target_store.logo)) //(!(target_store.logo == update.logo || update.logo.Contains(target_store.logo)))
                target_store.logo = update.logo != null ? ImageController.UploadFile(update.logo, "logo" + target_store.s_id) : null;

            if (target_store.banner_img == null || !(update.banner + "").Contains(target_store.banner_img))
                target_store.banner_img = update.banner != null ? ImageController.UploadFile(update.banner, "banner" + target_store.s_id) : null;

            if (target_store.background_img == null || !(update.background + "").Contains(target_store.background_img)) //) CHANGED FOR PARTIAL URLS
                target_store.background_img = update.background != null ? ImageController.UploadFile(update.background, "background" + target_store.s_id) : null;

            //update social media
            foreach (SocialMediaModel sm in update.social_media)
            {
                Store_Contact ssm = db.Store_Contact.FirstOrDefault(q => q.store == update.id && q.Contact.caption == sm.type);

                bool add_new_sm = false;
                if (ssm == null)
                {
                    add_new = true;
                    ssm = new Store_Contact();
                }
                ssm.value = sm.url;

                if (add_new_sm) db.Store_Contact.Add(ssm);
            }

            db.SaveChanges();

            return Json(target_store.name_space, JsonRequestBehavior.AllowGet);
        }
        public RecommendationModel(int p_id, SIEBUEntities db = null)
        {
            if (db == null) db = new SIEBUEntities();
            Product p = db.Products.Where(pr => pr.p_id == p_id).FirstOrDefault();
            id = p.p_id;
            store_id = p.store_id;
            name = p.name;
            status = p.Product_Status.st_id;
            description = p.description;
            short_description = p.short_description;
            cost = p.cost.Value;
            shipping_cost = p.shipping_cost.Value;
            avail_inventory = p.avail_inventory.Value;

            images = new List<ProductImageModel>();
            ProductImageModel pim = new ProductImageModel();
            pim.url = p.Product_Image.Count == 0 ? "/content/no-image" : p.Product_Image.OrderBy(pi => pi.sort).FirstOrDefault().url;
            images.Add(pim);

            if (p.dateadded.HasValue)
                dateadded = String.Format("{0:MMMM d, yyyy}", p.dateadded.Value);
            else dateadded = "N/A";

            store = new StoreModel();
            store.name = p.Store.name;
            store.store_namespace = p.Store.name_space;
        }