Example #1
0
        public bool CreateVibe(VibeCreate model, HttpPostedFileBase file)
        {
            model.Image = ConvertToBytes(file);
            var    ctx = new ApplicationDbContext();
            string username;

            UserInfoDetail getUser;

            var userInfoService = new UserInfoService(_userID);

            if (userInfoService.GetUsersByUserId(_userID) == null)
            {
                username = _username;
            }
            else
            {
                getUser  = userInfoService.GetUsersByUserId(_userID);
                username = getUser.Username;
            }

            var entity =
                new Vibe()
            {
                Id          = _userID,
                Username    = username,
                Title       = model.Title,
                Location    = model.Location,
                Image       = model.Image,
                Description = model.Description,
                Tags        = model.Tags,
                Private     = model.Private,
                DateCreated = DateTimeOffset.UtcNow
            };

            if (userInfoService.GetUsersByUserId(_userID) != null)
            {
                getUser = userInfoService.GetUsersByUserId(_userID);
                getUser.Vibes.Add(entity);
            }
            using (ctx)
            {
                ctx.Vibes.Add(entity);

                return(ctx.SaveChanges() == 1);
            }
        }
Example #2
0
        public ActionResult Create(VibeCreate vibe)
        {
            if (ModelState.IsValid)
            {
                HttpPostedFileBase file = Request.Files["VibeImage"];

                var service = CreateVibeService().CreateVibe(vibe, file);
                if (service)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
            }
            return(View(vibe));
        }