示例#1
0
        public async Task<ActionResult> Edit([Bind(Include = "IdUserCompany,IdUser,IdCompany,IsAdmin,IdStore")] userCompany userCompany, bool? isAdminBO)
        {
            if (ModelState.IsValid)
            {
                var user = db.UserProfile.Where(up => up.UserId.Equals(userCompany.IdUser)).FirstOrDefault();
                if (new CuponeraPrincipal(new CuponeraIdentity(User.Identity)).IsInRole("admin"))
                {
                    if ((bool)isAdminBO)
                    {
                        AddUserToCompany(user);
                    }
                    else
                    {
                        RemoveUserToCompany(user);
                    }
                }

                db.Entry(userCompany).State = EntityState.Modified;
                await db.SaveChangesAsync();

                if (user.Active == null || !(bool)user.Active)
                {
                    EmailHelper.SendNewUserActivation(userCompany.UserProfile.Email, GetToken(user.UserId));
                }

                return RedirectToAction("Index");
            }
            GetCompany(userCompany);
            GetStore(userCompany);
            GetUsers(userCompany);
            ViewBag.IdUserCompany = new SelectList(db.userCompany, "IdUserCompany", "IdUserCompany", userCompany.IdUserCompany);
            return View(userCompany);
        }
示例#2
0
        public async Task <ActionResult> Edit([Bind(Include = "IdPreHomeImage,Active,CreationDatetime,ModificationDatetime,DeletionDatetime,ImagePath,Latitude,Longitude")] preHomeImages prehomeimages)
        {
            if (ModelState.IsValid)
            {
                db.Entry(prehomeimages).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(prehomeimages));
        }
示例#3
0
        public async Task <ActionResult> Edit([Bind(Include = "IdSubCategory,Name,IdCategory")] subcategory subcategory)
        {
            if (ModelState.IsValid)
            {
                db.Entry(subcategory).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(subcategory));
        }
示例#4
0
        public async Task <ActionResult> Edit([Bind(Include = "IdCompany,Name,Contact,Telephone,Email,CreationDatetime,ModificationDatetime,DeletionDatetime")] company company)
        {
            if (ModelState.IsValid)
            {
                db.Entry(company).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(company));
        }
示例#5
0
        public async Task <ActionResult> Edit([Bind(Include = "IdCategory,Name,ImagePath,CreationDatetime,ModificationDatetime,DeletionDatetime")] category category, List <HttpPostedFileBase> fileUpload)
        {
            if (ModelState.IsValid)
            {
                if (fileUpload.Count > 0)
                {
                    category.ImagePath = GeneratePhisicalFile(fileUpload.FirstOrDefault());
                }
                db.Entry(category).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(category));
        }
示例#6
0
        public async Task <ActionResult> Edit([Bind(Include = "IdSubscription,Name,SortFactor,Duration")] subscription subscription, string Pricing, List <HttpPostedFileBase> fileUpload)
        {
            if (ModelState.IsValid)
            {
                if (!String.IsNullOrEmpty(Pricing))
                {
                    subscription.Pricing = Convert.ToDecimal(Pricing);
                }
                if (fileUpload.Count > 0)
                {
                    subscription.Icon = GeneratePhisicalFile(fileUpload.FirstOrDefault());
                }

                db.Entry(subscription).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(subscription));
        }
示例#7
0
        public async Task <ActionResult> Edit([Bind(Include = "IdState,Name,Link")] state state, string Latitude, string Longitude, string HomeBannerLink, string ListBannerLink, List <HttpPostedFileBase> ListBannerImage, List <HttpPostedFileBase> HomeBannerImage, string deletedBannerHome, string deletedBannerList)
        {
            if (ModelState.IsValid)
            {
                if (Latitude != null)
                {
                    state.Latitude = Convert.ToDouble(Latitude.Replace(".", ","));
                }
                if (Longitude != null)
                {
                    state.Longitude = Convert.ToDouble(Longitude.Replace(".", ","));
                }

                this.InsertBanners(state.IdState, HomeBannerLink, ListBannerLink, HomeBannerImage, ListBannerImage, deletedBannerHome == "on", deletedBannerList == "on");

                db.Entry(state).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(state));
        }
示例#8
0
        public async Task <ActionResult> Edit([Bind(Include = "IdStore,Name,Address,ContactNumber,ZipCode,IdState,StoreHours,Email,FacebookUrl,WhatsApp,Description,WebPage,Nextel,IdCompany")] store store, string Latitude, string Longitude, List <HttpPostedFileBase> fileUpload, string imagesToRemove, string ImagePath, string selectedCategories)
        {
            if (ModelState.IsValid)
            {
                var categories = GetNonRepeatedCategories(selectedCategories);

                fileUpload = FilterFiles(fileUpload);

                HttpPostedFileBase fileImagePath;
                if (String.IsNullOrEmpty(ImagePath) && fileUpload.Count() == 1)
                {
                    fileImagePath = fileUpload.FirstOrDefault();
                    fileUpload.RemoveAt(0);
                    ImagePath = GeneratePhisicalFile(fileImagePath);
                }

                string previousImagePath = db.store.Where(s => s.IdStore == store.IdStore).Select(s => s.ImagePath).FirstOrDefault();

                string[] images_to_remove = imagesToRemove.Split(new Char[] { ',' });
                RemoveImages(images_to_remove);

                string remainingImagePath = GetRemainImageName(store.IdStore);
                if (!string.IsNullOrEmpty(remainingImagePath))
                {
                    ImagePath = remainingImagePath;
                }

                store.ImagePath = ChangeCoverImage(previousImagePath, ImagePath, images_to_remove.Contains("main"), store.IdStore);



                if (Latitude != null)
                {
                    store.Latitude = Convert.ToDouble(Latitude.Replace(".", ","));
                }
                if (Longitude != null)
                {
                    store.Longitude = Convert.ToDouble(Longitude.Replace(".", ","));
                }

                if (!new CuponeraPrincipal(new CuponeraIdentity(User.Identity)).IsInRole("admin"))
                {
                    var stores = db.userCompany.Where(uc => uc.IdUser == CuponeraIdentity.CurrentUserId && uc.IdCompany == store.IdCompany);
                    if (stores.Count() == 0)
                    {
                        return(View(store));
                    }
                }



                db.Entry(store).State      = EntityState.Modified;
                store.ModificationDatetime = DateTime.Now;

                db.SaveChanges();
                //Save aditional images
                UploadImages(fileUpload, store.IdStore);

                InsertCategoriesFromStore(categories, store);

                return(RedirectToAction("Index"));
            }
            GetCompanies(store);
            GetCategories(store);
            return(View(store));
        }