コード例 #1
0
        public async Task<ActionResult> Create([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.userCompany.Add(userCompany);
                await db.SaveChangesAsync();
                EmailHelper.SendNewUserActivation(user.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
ファイル: preHomeController.cs プロジェクト: dcohan/Weenty
        public async Task <ActionResult> Create([Bind(Include = "IdPreHomeImage,Active,CreationDatetime,ModificationDatetime,DeletionDatetime,ImagePath,Latitude,Longitude")] preHomeImages prehomeimages)
        {
            if (ModelState.IsValid)
            {
                db.preHomeImages.Add(prehomeimages);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(prehomeimages));
        }
コード例 #3
0
        public async Task <ActionResult> Create([Bind(Include = "Name,IdCategory")] subcategory subcategory)
        {
            if (ModelState.IsValid)
            {
                db.subcategory.Add(subcategory);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(subcategory));
        }
コード例 #4
0
ファイル: companyController.cs プロジェクト: dcohan/Weenty
        public async Task <ActionResult> Create([Bind(Include = "IdCompany,Name,Contact,Telephone,Email,CreationDatetime,ModificationDatetime,DeletionDatetime")] company company)
        {
            if (ModelState.IsValid)
            {
                db.company.Add(company);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(company));
        }
コード例 #5
0
        public async Task <ActionResult> Create([Bind(Include = "Name")] category category, List <HttpPostedFileBase> fileUpload)
        {
            if (ModelState.IsValid)
            {
                fileUpload = FilterFiles(fileUpload);
                if (fileUpload.Count() == 1)
                {
                    category.ImagePath = GeneratePhisicalFile(fileUpload.FirstOrDefault());
                }

                db.category.Add(category);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
コード例 #6
0
ファイル: storeController.cs プロジェクト: dcohan/Weenty
        // GET: store/Delete/5
        public async Task <ActionResult> Delete(int id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            store store = await db.store.FindAsync(id);

            if (store == null)
            {
                return(HttpNotFound());
            }

            store.DeletionDatetime = DateTime.Now;
            await db.SaveChangesAsync();


            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
コード例 #7
0
        public async Task <ActionResult> Create([Bind(Include = "Name,SortFactor,Duration")] subscription subscription, string Pricing, List <HttpPostedFileBase> fileUpload)
        {
            if (ModelState.IsValid)
            {
                if (!String.IsNullOrEmpty(Pricing))
                {
                    subscription.Pricing = Convert.ToDecimal(Pricing);
                }

                fileUpload = FilterFiles(fileUpload);
                if (fileUpload.Count() == 1)
                {
                    subscription.Icon = GeneratePhisicalFile(fileUpload.FirstOrDefault());
                }


                db.subscription.Add(subscription);
                await db.SaveChangesAsync();

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

                db.state.Add(state);

                await db.SaveChangesAsync();

                this.InsertBanners(state.IdState, HomeBannerLink, ListBannerLink, HomeBannerImage, ListBannerImage);
                return(RedirectToAction("Index"));
            }

            return(View(state));
        }
コード例 #9
0
        // PUT: odata/store(5)
        public async Task <IHttpActionResult> Put([FromODataUri] int key, Delta <store> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            store store = await db.store.FindAsync(key);

            if (store == null)
            {
                return(NotFound());
            }

            patch.Put(store);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!storeExists(key))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Updated(store));
        }
コード例 #10
0
        // PUT: odata/companySubscription(5)
        public async Task <IHttpActionResult> Put([FromODataUri] int key, Delta <companySubscription> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            companySubscription companySubscription = await db.companySubscription.FindAsync(key);

            if (companySubscription == null)
            {
                return(NotFound());
            }

            patch.Put(companySubscription);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!companySubscriptionExists(key))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Updated(companySubscription));
        }
コード例 #11
0
        public async Task <ActionResult> Index(int subscriptions, int[] companies, DateTime?endDate)
        {
            int duration = 0;

            if (!endDate.HasValue)
            {
                var subscription = db.subscription.Where(s => s.IdSubscription == subscriptions);
                duration = subscription.FirstOrDefault().Duration;
            }

            for (int a = 0; a < companies.Count(); a++)
            {
                IEnumerable <companySubscription> companySubscription = db.companySubscription;
                companySubscription = companySubscription.Where(cs => cs.IdCompany == companies[a]);

                if (companySubscription != null && companySubscription.Count() > 0)
                {
                    var cs = companySubscription.FirstOrDefault();
                    cs.IdSubscription = subscriptions;
                    if (endDate.HasValue)
                    {
                        cs.EndDate = endDate.Value;
                    }
                    cs.ModificationDatetime = DateTime.Now;
                }
                else
                {
                    var cs = new companySubscription();
                    cs.IdSubscription   = subscriptions;
                    cs.IdCompany        = companies.ElementAt(a);
                    cs.CreationDatetime = DateTime.Now;
                    cs.EndDate          = endDate.HasValue ? endDate.Value : DateTime.Now.AddDays(duration);

                    db.companySubscription.Add(cs);
                }

                await db.SaveChangesAsync();
            }
            return(RedirectToAction("Index"));
        }