Beispiel #1
0
        public async Task <IActionResult> Create(Matchdto match)
        {
            if (ModelState.IsValid)
            {
                var directory = Path.Combine(_hosting.WebRootPath, "Home", "images", "Matches");
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }
                if (match.MatchImage != null)
                {
                    match.FileName = match.MatchImage.FileName;
                    using (var stream = new FileStream(Path.Combine(directory, match.FileName), FileMode.Create))
                    {
                        await match.MatchImage.CopyToAsync(stream);
                    }
                }

                var users = await _userManager.GetUserAsync(HttpContext.User);

                match.UserId = users.Id;
                _context.Matches.Add(_mapper.Map <Match>(match));
                await _context.SaveChangesAsync();

                return(Json(ResponseHelper.Success()));
            }
            return(Json(ResponseHelper.UnSuccess()));
        }
Beispiel #2
0
        public async Task <IActionResult> Edit(Matchdto match)
        {
            if (ModelState.IsValid)
            {
                var    form      = Request.Form;
                byte[] fileBytes = null;
                if (match.MatchImage != null)
                {
                    using (var stream = match.MatchImage.OpenReadStream())
                    {
                        fileBytes = ReadStream(stream);
                    }
                }
                var users = await _userManager.GetUserAsync(HttpContext.User);

                match.UserId    = users.Id;
                match.MatchLogo = fileBytes ?? null;
                _context.Update(_mapper.Map <Match>(match));
                await _context.SaveChangesAsync();

                return(Json(ResponseHelper.UpdateSuccess()));
            }
            return(Json(ResponseHelper.UpdateUnSuccess()));
        }