Beispiel #1
0
 public WeekPlan(WeekPlanCreate command)
 {
     ClientId    = command.ClientId;
     Plan        = command.Plan;
     WeekNumber  = command.WeekNumber;
     ManagerType = command.ManagerType;
     Date        = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
     PlanTitle   = command.PlanTitle;
 }
Beispiel #2
0
        public async Task <IActionResult> Post([FromBody] WeekPlanCreate command)
        {
            var weekPlan = await _context.Set <WeekPlan>()
                           .FirstOrDefaultAsync(x => x.ClientId == command.ClientId &&
                                                DateHelper.IsCurrentMonth(x.Date) &&
                                                x.WeekNumber == 2 &&
                                                x.ManagerType == command.ManagerType);

            if (weekPlan != null)
            {
                return(BadRequest("План на эту неделю уже существует"));
            }

            var newWeekPlan = await _context.Set <WeekPlan>()
                              .AddAsync(new WeekPlan(command));

            await _context.SaveChangesAsync();

            var result = newWeekPlan.Entity;

            return(Ok(result));
        }