public async Task <IActionResult> Put(int id, [FromBody] HabitModel habitModel) { RepeatDays?result = null; if (habitModel.RepeatDays != null) { RepeatDays[] repeatDays = habitModel.RepeatDays.Select(o => (RepeatDays)o).ToArray(); foreach (RepeatDays f in repeatDays) { result |= (RepeatDays)f; } if (habitModel.Repeat == null || habitModel.Repeat != Repeat.Weekly) { result = null; } } Habit habit = new Habit { Id = habitModel.Id, Name = habitModel.Name, Description = habitModel.Description, StartDate = habitModel.StartDate == null?dateTimeService.GetCurrentDateTime() : (DateTime)habitModel.StartDate, EndDate = habitModel.EndDate, Repeat = habitModel.Repeat == null ? Repeat.NoRepeat : (Repeat)habitModel.Repeat, RepeatDays = (RepeatDays?)result, Colour = habitModel.Colour, Mesurable = habitModel.Mesurable, NumberOfBlocks = habitModel.NumberOfBlocks, RepresentationOfBlocks = habitModel.RepresentationOfBlocks }; habitService.UpdateHabit(id, habit); return(NoContent()); }
public async Task <IActionResult> Post([FromBody] HabitModel habitModel) { RepeatDays[] repeatDays = habitModel.RepeatDays.Select(o => (RepeatDays)o).ToArray(); RepeatDays? result = null; foreach (RepeatDays f in repeatDays) { result |= (RepeatDays)f; } if (habitModel.Repeat == null || habitModel.Repeat != Repeat.Weekly) { result = null; } Habit habit = new Habit { Id = habitModel.Id, Name = habitModel.Name, Description = habitModel.Description, StartDate = habitModel.StartDate == null?dateTimeService.GetCurrentDateTime() : (DateTime)habitModel.StartDate, EndDate = habitModel.EndDate, Repeat = habitModel.Repeat == null? Repeat.NoRepeat :(Repeat)habitModel.Repeat, RepeatDays = (RepeatDays?)result, Colour = habitModel.Colour, Mesurable = habitModel.Mesurable, NumberOfBlocks = habitModel.NumberOfBlocks, RepresentationOfBlocks = habitModel.RepresentationOfBlocks }; return(CreatedAtAction("Get", new { id = habit.Id }, habitService.AddHabit(habit))); }
public IActionResult Get(int id) { var result = habitService.GetHabit(id); IEnumerable <int> repeatArrayInt = null; if (result.RepeatDays != null) { var repeatArray = habitService.GetFlags(result.RepeatDays); repeatArrayInt = repeatArray.Select(x => Convert.ToInt32(x)); } HabitModel habitModel = new HabitModel { Id = result.Id, Name = result.Name, Description = result.Description, StartDate = result.StartDate, EndDate = result.EndDate, Repeat = result.Repeat, RepeatDays = repeatArrayInt, Colour = result.Colour, Mesurable = result.Mesurable, NumberOfBlocks = result.NumberOfBlocks, RepresentationOfBlocks = result.RepresentationOfBlocks }; return(Ok(habitModel)); }
public BaseResponse <HabitModel> SaveHabit(HabitModel request) { return(base.Save <DC_Habit, HabitModel>(request, (q) => q.ID == request.ID)); }
public IHttpActionResult Post(HabitModel baseRequest) { var response = service.SaveHabit(baseRequest); return(Ok(response)); }