Exemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("ID,Top,Bottom,UserId, TopImage, TopName, BottomImage, BottomFile")] MixnMatch mixnMatch)
        {
            ViewBag.userid = _userManager.GetUserId(HttpContext.User);
            if (ModelState.IsValid)
            {
                //Get file based on chosen wardrobe
                string top = mixnMatch.Top;
                if (!String.IsNullOrEmpty(top))
                {
                    var usermatch = _context.Wardrobe.FirstOrDefault(m => m.Name.Contains(top));
                    mixnMatch.TopUrl  = usermatch.ImageUrl;
                    mixnMatch.TopFile = usermatch.FileName;
                }

                string bottom = mixnMatch.Bottom;
                if (!String.IsNullOrEmpty(top))
                {
                    var usermatch = _context.Wardrobe.FirstOrDefault(m => m.Name.Contains(bottom));
                    mixnMatch.BottomUrl  = usermatch.ImageUrl;
                    mixnMatch.BottomFile = usermatch.FileName;
                }
                _context.Add(mixnMatch);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(mixnMatch));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Top,Bottom,UserId")] MixnMatch mixnMatch)
        {
            if (id != mixnMatch.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(mixnMatch);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MixnMatchExists(mixnMatch.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(mixnMatch));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("ID,Top,Bottom,UserId")] MixnMatch mixnMatch)
        {
            ViewBag.userid = _userManager.GetUserId(HttpContext.User);
            if (ModelState.IsValid)
            {
                _context.Add(mixnMatch);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(mixnMatch));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Top,Bottom,UserId, TopImage, TopName, BottomImage, BottomFile")] MixnMatch mixnMatch)
        {
            if (id != mixnMatch.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    //Get file based on chosen wardrobe
                    string top = mixnMatch.Top;
                    if (!String.IsNullOrEmpty(top))
                    {
                        var usermatch = _context.Wardrobe.FirstOrDefault(m => m.Name.Contains(top));
                        mixnMatch.TopUrl  = usermatch.ImageUrl;
                        mixnMatch.TopFile = usermatch.FileName;
                    }

                    string bottom = mixnMatch.Bottom;
                    if (!String.IsNullOrEmpty(top))
                    {
                        var usermatch = _context.Wardrobe.FirstOrDefault(m => m.Name.Contains(bottom));
                        mixnMatch.BottomUrl  = usermatch.ImageUrl;
                        mixnMatch.BottomFile = usermatch.FileName;
                    }

                    _context.Update(mixnMatch);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MixnMatchExists(mixnMatch.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(mixnMatch));
        }