Esempio n. 1
0
        public void ExcluirProduto(Produto produto)
        {
            using var db = new Data.ApplicationDbContext();

            var produtoExcluir = db.Produtos.Find(produto.Id);

            db.Remove(produtoExcluir);
            db.SaveChanges();
        }
Esempio n. 2
0
        public async Task <IActionResult> AddandRemoveSchedule(Schedule s)
        {
            try
            {
                var user = await GetCurrentUserAsync();

                var userId = user?.Id;
                var slots  = _context.Student.Where(p => p.IdentityId.Equals(userId)).FirstOrDefault();
                s.StudentId = slots.Id;
                var schedule = _context.Slots.Where(p => p.Id == s.SlotId).FirstOrDefault();
                var studentslotvalidation = _context.Schedule.Where(p => p.StudentId.Equals(s.StudentId) && p.Date == schedule.ScheduleDateTime && schedule.Id != p.SlotId).FirstOrDefault();
                if (studentslotvalidation == null)
                {
                    var slot = _context.Schedule.Where(p => p.StudentId.Equals(s.StudentId) && p.Date == s.Date).FirstOrDefault();
                    if (slot == null)
                    {
                        s.CreatedBy   = "test";
                        s.CreatedDate = System.DateTime.Now;
                        s.UpdatedBy   = "test1";
                        s.UpdatedDate = System.DateTime.Now;
                        _context.Add(s);
                        _context.SaveChanges();
                        return(Json(new { success = true }));
                    }
                    else
                    {
                        _context.Remove(slot);
                        _context.SaveChanges();
                        return(Json(new { success = false }));
                    }
                }
                else
                {
                    return(Json(new { success = studentslotvalidation }));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async Task <IActionResult> DeleteAuthor(int id)
        {
            Author existingAuthor = await _db.Authors
                                    .Where(a => a.AuthorId == id)
                                    .FirstOrDefaultAsync();

            if (existingAuthor == null)
            {
                return(NotFound());
            }

            try
            {
                _db.Remove(existingAuthor);
                await _db.SaveChangesAsync();

                return(NoContent());
            }
            catch (DbUpdateException)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  _errorMessageSavingData));
            }
        }
        public async Task <IActionResult> DeleteWork(int id)
        {
            Work existingWork = await _db.Works
                                .Where(w => w.WorkId == id)
                                .FirstOrDefaultAsync();

            if (existingWork == null)
            {
                return(NotFound());
            }

            try
            {
                _db.Remove(existingWork);
                await _db.SaveChangesAsync();

                return(NoContent());
            }
            catch (DbUpdateException)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  _errorMessageSavingData));
            }
        }
 public void Remove(Playlist playlist)
 {
     _dbContext.Remove(playlist);
 }