Exemplo n.º 1
0
        public ActionResult Add(AddInterestBm bm)
        {
            if (this.ModelState.IsValid)
            {
                HttpPostedFileBase file = this.Request.Files["url"];

                if (file == null || !file.ContentType.Contains("image"))
                {
                    this.ModelState.AddModelError("url", "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);
                    bm.Url = imageUrl;

                    var userId = this.User.Identity.GetUserId();
                    this.service.AddInterest(bm, userId);

                    return(this.RedirectToAction("All", "Interests"));
                }
            }

            AddInterestVm vm = Mapper.Map <AddInterestBm, AddInterestVm>(bm);

            return(this.View("Add", vm));
        }
Exemplo n.º 2
0
        public void AddInterest(AddInterestBm bm, string userId)
        {
            ApplicationUser currentUser = this.Context.Users.Find(userId);
            Interest        sale        = Mapper.Map <AddInterestBm, Interest>(bm);

            sale.PostDate = DateTime.Now;
            currentUser.Interests.Add(sale);
            this.Context.SaveChanges();
        }