Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,FullName,Email,Age,SerialNum,Entries,Wins")] Submission submission)
        {
            if (id != submission.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(submission);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SubmissionExists(submission.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(submission));
        }
Пример #2
0
        public Submission DrawWinner()
        {
            var random = new Random();
            List <Submission> allSubmissions = GetSubmissions();
            int        index = random.Next(allSubmissions.Count);
            Submission sub   = allSubmissions[index];

            sub.Wins++;
            _db.Update(sub);
            _db.SaveChangesAsync();


            return(sub);
        }
        public virtual void Update(T entity)
        {
            try
            {
                if (entity == null)
                {
                    throw new ArgumentNullException(nameof(entity));
                }

                _context.Update(entity);
                //_context.Entry(entity).State = EntityState.Detached;

                //_context.Entry(entity).State = EntityState.Modified;

                _context.SaveChanges();
            }
            catch (InvalidOperationException dbEx)
            {
                throw new Exception(dbEx.Message);
            }
        }