示例#1
0
 private void AddUserToCompany(Cuponera.Entities.UserProfile user)
 {
     var adminRole = db.webpages_Roles.Where(r => r.RoleName.Equals("admin")).FirstOrDefault();
     if (user.webpages_Roles.Where(ur => ur.RoleId.Equals(adminRole.RoleId)).FirstOrDefault() == null)
     {
         user.webpages_Roles.Add(adminRole);
         db.SaveChanges();
     }
 }
示例#2
0
        public async Task <ActionResult> Create([Bind(Include = "Name,Address,ContactNumber,ZipCode,IdState,IdCompany,StoreHours,Email,FacebookUrl,WhatsApp,Description,WebPage,Nextel")] store store, string Latitude, string Longitude, List <HttpPostedFileBase> fileUpload, string selectedCategories)
        {
            if (ModelState.IsValid)
            {
                var categories = GetNonRepeatedCategories(selectedCategories);

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

                fileUpload = FilterFiles(fileUpload);
                string             imagePath = null;
                HttpPostedFileBase fileImagePath;
                if (fileUpload.Count() == 1)
                {
                    fileImagePath = fileUpload.FirstOrDefault();
                    fileUpload.RemoveAt(0);
                    imagePath = GeneratePhisicalFile(fileImagePath);
                }

                store.ImagePath = imagePath;

                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.store.Add(store);
                db.SaveChanges();

                InsertCategoriesFromStore(categories, store);

                //Save aditional images
                UploadImages(fileUpload, store.IdStore);
                return(RedirectToAction("Index"));
            }

            GetCompanies(store);
            GetCategories(store);
            return(View(store));
        }
示例#3
0
        public void UploadImages(List <HttpPostedFileBase> fileUpload, int IdObject)
        {
            if (fileUpload.Count() == 0)
            {
                return;
            }

            List <HttpPostedFileBase> finalFilesToUpload = fileUpload;

            foreach (HttpPostedFileBase item in fileUpload)
            {
                if (item != null)
                {
                    //Save phisical File & generate virtual Path
                    var virtualPath = GeneratePhisicalFile(item);

                    images i = null;
                    switch (_definedType)
                    {
                    case UploadImagesEnum.offer:
                        i = new images()
                        {
                            IdOffer = IdObject, ImagePath = virtualPath
                        };
                        break;

                    case UploadImagesEnum.product:
                        i = new images()
                        {
                            IdProduct = IdObject, ImagePath = virtualPath
                        };
                        break;

                    case UploadImagesEnum.store:
                        i = new images()
                        {
                            IdStore = IdObject, ImagePath = virtualPath
                        };
                        break;
                    }

                    //Save Images
                    db.images.Add(i);
                    db.SaveChanges();
                }
            }
        }
示例#4
0
        public ActionResult RegisterConfirmation(string Id) //Id=ConfirmationToken
        {
            if (WebSecurity.ConfirmAccount(Id))
            {
                //Activar el usuario
                db.UserProfile.Where(u => u.UserId.Equals(db.webpages_Membership.Where(m => m.ConfirmationToken.Equals(Id)).FirstOrDefault().UserId)).FirstOrDefault().Active = true;
                db.SaveChanges();

                //get userId and perfom some operations related to it
                return(RedirectToAction("ConfirmationSuccess"));
            }
            return(RedirectToAction("ConfirmationFailure"));
        }