public async Task <IActionResult> Save(DiaryRequestModel DiaryRequest) { try { DiaryRequest.CreatedBy = this.UserId; var DiaryList = await _diaryService.GetByUserId(this.UserId); int IsAdded = DiaryList.Where(a => a.CreatedOn.Value.Date == DiaryRequest.CreatedOn.Value.Date).Count(); if (IsAdded > 0) { return(Ok(new { status = HttpStatusCode.InternalServerError, valid = false, type = "alert", msg = "You can add one page per day!" })); } var DiaryDto = _mapper.Map <Diary>(DiaryRequest); var result = await _diaryService.AddDiary(DiaryDto); if (result) { return(Ok(new { status = HttpStatusCode.OK, valid = true, msg = "Diary added successfully" })); } return(Ok(new { status = HttpStatusCode.InternalServerError, valid = true, msg = "Something went wrong" })); } catch (Exception ex) { return(Ok(new { status = HttpStatusCode.InternalServerError, valid = true, msg = ex.InnerException.Message })); } }
public async Task <IActionResult> AddDiary(CreateDiaryRequest request) { return(Ok(await _diaryService.AddDiary(request))); }