public bool Create(BienTheDTO bientheDto)
        {
            var item = CheckExistsTen(bientheDto.TenBienThe);

            if (item)
            {
                return(false);
            }
            var bienthe = new BienThe
            {
                MaBienThe   = Guid.NewGuid(),
                TenBienThe  = bientheDto.TenBienThe,
                MaChatLuong = bientheDto.MaChatLuong,
                MaGiong     = bientheDto.MaGiong,
                MauSac      = bientheDto.MauSac,
                MaChungLoai = bientheDto.MaChungLoai,

                TinhTrang = Convert.ToBoolean(bientheDto.TinhTrang),
                MoTa      = bientheDto.MoTa
            };

            _bientheRepository.Insert(bienthe);
            _unitOfWork.Commit();
            return(true);
        }
 public async Task <BaseResponse> Update(BienTheDTO bientheDTO)
 {
     try
     {
         var result = _bientheService.Update(bientheDTO);
         if (result)
         {
             return(await Task.FromResult(new BaseResponse(result)));
         }
         return(await Task.FromResult(new BaseResponse(Message.UpdateNotSuccess, false)).ConfigureAwait(false));
     }
     catch (Exception e)
     {
         return(await Task.FromResult(new BaseResponse(Message.UpdateNotSuccess, false)).ConfigureAwait(false));
     }
 }
 public async Task <BaseResponse> InsertAll(BienTheDTO entity)
 {
     try
     {
         var result = _bientheService.Create(entity);
         if (result)
         {
             return(await Task.FromResult(new BaseResponse(result)));
         }
         return(await Task.FromResult(new BaseResponse(Message.CreateNotSuccess)));
     }
     catch (Exception e)
     {
         return(await Task.FromResult(new BaseResponse(Message.CreateNotSuccess)));
     }
 }
        public bool Update(BienTheDTO bientheDto)
        {
            try
            {
                var bienthe = _bientheRepository.GetById(bientheDto.MaBienThe);
                if (bienthe == null)
                {
                    return(false);
                }
                // Update chi tiet
                bienthe.MaBienThe   = bientheDto.MaBienThe;
                bienthe.TenBienThe  = bientheDto.TenBienThe.ToLower();
                bienthe.MaChungLoai = bientheDto.MaChungLoai;
                bienthe.MaChatLuong = bientheDto.MaChatLuong;
                bienthe.MaGiong     = bientheDto.MaGiong;
                bienthe.MoTa        = bientheDto.MoTa;
                bienthe.MauSac      = bientheDto.MauSac;
                bienthe.TinhTrang   = bientheDto.TinhTrang;
                //update thuốc điều trị
                //var thuocdieutriOld = _thuocdieutriRepository.GetMany(p => p.MaBenh == benh.MaBenh).ToList();
                //_thuocdieutriRepository.RemoveMultiple(thuocdieutriOld);

                //var thuocs = _thuocRepository.GetMany(r => benhDto.MaThuocs.Contains(r.MaThuoc.ToString()));
                //foreach (var thuoc in thuocs)
                //{
                //    var thuocdieutri = new ThuocDieuTri { MaBenh = benh.MaBenh, MaThuoc = thuoc.MaThuoc };

                //    _thuocdieutriRepository.Insert(thuocdieutri);
                //}
                // update user
                _bientheRepository.Update(bienthe);
                _unitOfWork.Commit();
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }