Exemplo n.º 1
0
        public async Task <DetailInTreeView> UpdateDetailNameAsync(int detailId, string newDetailName)
        {
            var retrievedDetailToUpdate = await _context.Details
                                          .SingleOrDefaultAsync(x => x.DetailId == detailId)
                                          .ConfigureAwait(false);

            if (retrievedDetailToUpdate == null)
            {
                return(null);
            }

            var isUniqueName = await IsUniqueDetailNameAsync(newDetailName);

            if (!isUniqueName)
            {
                return(null);
            }

            retrievedDetailToUpdate.Name = newDetailName;

            await _context.SaveChangesAsync().ConfigureAwait(false);

            return(new DetailInTreeView
            {
                DetailId = retrievedDetailToUpdate.DetailId,
                Name = retrievedDetailToUpdate.Name
            });
        }
Exemplo n.º 2
0
        public async Task <IActionResult> CreateTask(DayModel dayModel)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("ShowDay", new { dayDate = dayModel.CurrentDate }));
            }
            var time = dayModel.Date;
            var date = DateTime.Parse(dayModel.CurrentDate);

            dayModel.Date = new DateTime(date.Year, date.Month, date.Day, time.Hour, time.Minute, time.Second);
            var task = new Task
            {
                Text = dayModel.Text,
                Date = dayModel.Date
            };

            _context.Add(task);
            await _context.SaveChangesAsync();

            return(RedirectToAction("ShowDay", new { dayDate = dayModel.Date.ToShortDateString() }));
        }
Exemplo n.º 3
0
 public async Task CreateAsync(T entity)
 {
     DbContext.Set <T>().Add(entity);
     await DbContext.SaveChangesAsync();
 }
Exemplo n.º 4
0
 public async Task <int> SaveAsync() => await _context.SaveChangesAsync();