public IActionResult Update(WeeklyPlanDto weeklyPlanDto) { var isOver = _weeklyPlanService.IsOver(weeklyPlanDto.Id); if (!isOver.Success) { return(BadRequest(isOver.Message)); } var planExist = _weeklyPlanService.PlanExist(weeklyPlanDto); if (!planExist.Success) { return(BadRequest(planExist.Message)); } var result = _weeklyPlanService.Update(weeklyPlanDto); if (result.Success) { return(Ok(result.Message)); } return(BadRequest(result.Message)); }
public IResult PlanExist(WeeklyPlanDto weeklyPlanDto) { var userPlans = _weeklyPlanDal.GetList(w => w.UserId.Equals(UserId) && w.Year.Equals(weeklyPlanDto.Year) && w.WeekNumber.Equals(weeklyPlanDto.WeekNumber) && !w.Id.Equals(weeklyPlanDto.Id)); if (userPlans.Any()) { return(new ErrorResult(Messages.WeeklyPlanExist)); } return(new SuccessResult()); }
public IResult Update(WeeklyPlanDto weeklyPlanDto) { var plan = _weeklyPlanDal.Get(w => w.Id == weeklyPlanDto.Id); plan.Description = weeklyPlanDto.Description; plan.ImportanceTypeId = weeklyPlanDto.ImportanceTypeId; plan.WeekNumber = weeklyPlanDto.WeekNumber; plan.Name = weeklyPlanDto.Name; plan.Year = weeklyPlanDto.Year; _weeklyPlanDal.Update(plan); return(new SuccessResult(Messages.WeeklyPlanUpdated)); }
public IResult Add(WeeklyPlanDto weeklyPlanDto) { _weeklyPlanDal.Add(new WeeklyPlan { UserId = UserId, Description = weeklyPlanDto.Description, ImportanceTypeId = weeklyPlanDto.ImportanceTypeId, WeekNumber = weeklyPlanDto.WeekNumber, Name = weeklyPlanDto.Name, Year = weeklyPlanDto.Year, }); return(new SuccessResult(Messages.WeeklyPlanAdded)); }
public IActionResult Add(WeeklyPlanDto weeklyPlanDto) { weeklyPlanDto.Id = 0; var planExist = _weeklyPlanService.PlanExist(weeklyPlanDto); if (!planExist.Success) { return(BadRequest(planExist.Message)); } var result = _weeklyPlanService.Add(weeklyPlanDto); if (result.Success) { return(Ok(result.Message)); } return(BadRequest(result.Message)); }
public IResult MonthlyPlanIsAppropriate(WeeklyPlanDto weeklyPlanDto) { var monthlyPlan = _monthlyPlanDal.Get(w => w.Id == weeklyPlanDto.MonthlyPlanId); if (monthlyPlan != null) { var firstDateOfWeek = DateTime.Today.FirstDateOfWeek(weeklyPlanDto.Year, weeklyPlanDto.WeekNumber); var lastDateOfWeek = firstDateOfWeek.AddDays(6); var thursdayDateOfWeek = firstDateOfWeek.AddDays(3); var firstDateOfMonth = new DateTime(monthlyPlan.Year, monthlyPlan.Month, 1); var lastDateOfMonth = firstDateOfMonth.AddMonths(1).AddDays(-1); if (!(firstDateOfWeek <= firstDateOfMonth && firstDateOfMonth <= thursdayDateOfWeek) && !(thursdayDateOfWeek >= lastDateOfMonth && lastDateOfMonth >= lastDateOfWeek)) { return(new ErrorResult(Messages.WeeklyPlanNotAppropriate)); } } return(new SuccessResult()); }