Beispiel #1
0
        public async Task <Response <string> > UpsertToothRequest(UpsertToothRequest request)
        {
            var tooth = await _unitOfWork.ToothChildRepository.FirstAsync(x => x.ChildId == request.ChildId && x.ToothId == request.ToothId);

            if (tooth == null)
            {
                var toothChild = new ToothChild
                {
                    ToothId   = request.ToothId,
                    ChildId   = request.ChildId,
                    GrownDate = request.GrownDate,
                    Note      = request.Note,
                    ImageUrl  = request.ImageURL,
                    GrownFlag = request.GrownFlag,
                };
                await _unitOfWork.ToothChildRepository.AddAsync(toothChild);

                await _unitOfWork.SaveAsync();

                return(new Response <string>(null, "Thêm răng thành công, id: " + toothChild.Id));
            }

            tooth.ToothId   = request.ToothId;
            tooth.ChildId   = request.ChildId;
            tooth.GrownDate = request.GrownDate;
            tooth.Note      = request.Note;
            tooth.ImageUrl  = request.ImageURL;
            tooth.GrownFlag = request.GrownFlag;;

            _unitOfWork.ToothChildRepository.UpdateAsync(tooth);
            await _unitOfWork.SaveAsync();

            return(new Response <string>(tooth.Id.ToString(), "Cập nhật răng thành công"));
        }
Beispiel #2
0
        public async Task <IActionResult> UpsertToothRequest(string toothId, UpsertToothRequest request)
        {
            if (toothId != request.ToothId)
            {
                return(BadRequest());
            }

            return(Ok(await _toothService.UpsertToothRequest(request)));
        }