public async Task<Response<string>> UpdateChildHistory(ChildHistoryRequest request, UpdateChildHistoryRequest updateRequest) { DateTimeOffset dataDate = DateTimeOffset.ParseExact(request.Date, "dd/MM/yyyy", CultureInfo.InvariantCulture).ToOffset(new TimeSpan(7, 0, 0)); var childHistory = await _unitOfWork.ChildHistoryRepository.FirstAsync(x => x.ChildId == request.ChildId && x.Date == dataDate.Date.ToString("dd'/'MM'/'yyyy")); if (childHistory != null) { childHistory.Height = updateRequest.Height; childHistory.Weight = updateRequest.Weight; childHistory.HeadCircumference = updateRequest.HeadCircumference; childHistory.AvgMilk = updateRequest.AvgMilk; childHistory.HourSleep = updateRequest.HourSleep; childHistory.WeekOlds = updateRequest.WeekOlds; _unitOfWork.ChildHistoryRepository.UpdateAsync(childHistory); await _unitOfWork.SaveAsync(); return new Response<string>(request.ChildId, $"Cập nhật thông tin em bé thành công, id: {request.ChildId}"); } childHistory = new ChildHistory { ChildId = request.ChildId, Date = dataDate.ToString("dd'/'MM'/'yyyy"), Height = updateRequest.Height, Weight = updateRequest.Weight, HeadCircumference = updateRequest.HeadCircumference, AvgMilk = updateRequest.AvgMilk, HourSleep = updateRequest.HourSleep, WeekOlds = updateRequest.WeekOlds }; await _unitOfWork.ChildHistoryRepository.AddAsync(childHistory); await _unitOfWork.SaveAsync(); return new Response<string>(null, $"Thêm thông tin bé thành công, id: \'{request.ChildId}\'"); }
public async Task <IActionResult> UpdateChildHistory([FromQuery] ChildHistoryRequest request, [FromBody] UpdateChildHistoryRequest updateRequest) { if (string.IsNullOrEmpty(request.ChildId) || request.ChildId != updateRequest.ChildId) { return(BadRequest(new Response <string>("ChildId not found"))); } else { if (!DateTimeOffset.TryParseExact(request.Date, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out _)) { return(BadRequest(new Response <string>("Incorrect date format"))); } } return(Ok(await _childHistoryService.UpdateChildHistory(request, updateRequest))); }