コード例 #1
0
ファイル: BenefitController.cs プロジェクト: windygu/PointEx
        public async Task <ActionResult> Edit(int id, BenefitForm benefitForm)
        {
            if (!ModelState.IsValid)
            {
                return(View(benefitForm));
            }

            var benefit = benefitForm.ToBenefit();

            await _benefitService.Edit(benefit, User, _currentUser.PointexUser.Email, AppSettings.Theme);

            var successMessage = "Beneficio Editado";

            if (_currentUser.IsAnyAdminUser)
            {
                switch (benefit.StatusId)
                {
                case StatusEnum.Pending:
                    return(RedirectToAction("Index", "Benefit", new { Area = "Admin" }).WithSuccess(successMessage));

                case StatusEnum.Approved:
                    return(RedirectToAction("ApprovedBenefit", "Benefit", new { Area = "Admin" }).WithSuccess(successMessage));

                case StatusEnum.Rejected:
                    return(RedirectToAction("Rejected", "Benefit", new { Area = "Admin" }).WithSuccess(successMessage));
                }
            }

            return(RedirectToAction("Index", new BenefitListFiltersModel().GetRouteValues()).WithSuccess(successMessage));
        }
コード例 #2
0
        public ActionResult UploadImages(UploadBenefitImageForm uploadImagesForm)
        {
            if (uploadImagesForm.Files.All(f => f == null))
            {
                return(RedirectToAction("Index", new { benefitId = uploadImagesForm.Id }));
            }

            if (!ModelState.IsValid)
            {
                var benefit = _benefitService.GetById(uploadImagesForm.Id);
                uploadImagesForm.Benefit = benefit;
                return(View(uploadImagesForm));
            }

            List <BenefitFile> benefitFiles = new List <BenefitFile>();

            foreach (var file in uploadImagesForm.Files)
            {
                var benefitFile = new BenefitFile();
                benefitFile.BenefitId = uploadImagesForm.Id;
                benefitFile.File      = file.ToFile();
                benefitFiles.Add(benefitFile);
            }

            _benefitFileService.Create(benefitFiles);

            var b = _benefitService.GetById(uploadImagesForm.Id);

            b.StatusId = StatusEnum.Pending;

            _benefitService.Edit(b, User, _currentUser.PointexUser.Email, AppSettings.Theme);

            return(RedirectToAction("Index", new { benefitId = uploadImagesForm.Id }).WithSuccess("Imagenes subidas"));
        }