Exemplo n.º 1
0
        public ActionResult Edit(int id)
        {
            string userId = this.User.Identity.GetUserId();

            if (!this.service.InterestExists(id))
            {
                return(this.HttpNotFound("Interest not found."));
            }

            bool isValid = this.service.IsUserAuthenticatedToEditCurrent(id, userId);

            if (isValid)
            {
                EditInterestVm vm = this.service.GetEditVm(id);

                if (vm == null)
                {
                    return(this.HttpNotFound());
                }

                return(this.View(vm));
            }

            return(this.RedirectToAction("All"));
        }
Exemplo n.º 2
0
        public ActionResult EditPost(EditInterestBm bind)
        {
            if (this.ModelState.IsValid)
            {
                HttpPostedFileBase file = this.Request.Files["salePicture"];

                if (file == null || !file.ContentType.Contains("image"))
                {
                    this.ModelState.AddModelError("profilePicture", "Invalid image");
                }
                else
                {
                    var    pathToFolder = this.Server.MapPath("~/SalePictures");
                    string fileName     = Path.GetFileName(file.FileName);
                    string path         = this.service.GetAdequatePathToSave(pathToFolder, fileName);
                    file.SaveAs(path);

                    var imageUrl = this.service.GetImageUrl(path);
                    bind.SalePicture = imageUrl;

                    string currentUsername = this.User.Identity.Name;
                    this.service.EditInterest(bind, currentUsername);

                    return(this.RedirectToAction("Mine"));
                }
            }

            EditInterestVm vm = this.service.GetEditVm(bind.Id);

            return(this.View(vm));
        }
Exemplo n.º 3
0
        public EditInterestVm GetEditVm(int interestId)
        {
            Interest interest = this.Context.Interests.Find(interestId);

            if (interest == null)
            {
                return(null);
            }

            EditInterestVm vm = Mapper.Map <Interest, EditInterestVm>(interest);

            return(vm);
        }