コード例 #1
0
        public async Task<PartialViewResult> Create(TimeSheetEntry newEntry)
        {
            //todo refactor with Fluent Validations 
            //https://fluentvalidation.codeplex.com/
            var tses = await timeSheetRepository.FindAsync(
                    tse => DbFunctions.TruncateTime(tse.EntryDate) == DbFunctions.TruncateTime(newEntry.EntryDate));
            tses.Add(newEntry);
            var totalHours = tses.Sum(tse => tse.Duration);
            if (totalHours > 24)
            {
                ModelState.AddModelError("Duration", "How can you work more than the hours in the day?!!");
            }

            if (ModelState.IsValid)
            {
                timeSheetRepository.Add(newEntry);
                await SaveChangesAsync();
                if (ModelState.IsValid)
                {
                    var timeSheetEntry = new TimeSheetEntry()
                    {
                        ProjectId = newEntry.ProjectId,
                        PersonId = newEntry.PersonId,
                        EntryDate = newEntry.EntryDate
                    };
                    ModelState.Clear();
                    return PartialView(timeSheetEntry);
                }
            }
            return PartialView(newEntry);
        }
コード例 #2
0
 public TimeSheetEntry Add(TimeSheetEntry newEntry)
 {
     return uow.Set<TimeSheetEntry>().Add(newEntry);
 }