public bool Create(ThuocDTO thuocDto)
        {
            try
            {
                var item = CheckExistsTenThuoc(thuocDto.TenThuoc);
                if (item)
                {
                    return(false);
                }
                var thuoc = new Thuoc
                {
                    MaThuoc  = Guid.NewGuid(),
                    TenThuoc = thuocDto.TenThuoc,
                    CongDung = thuocDto.CongDung,
                    CachDung = thuocDto.CachDung,
                    HinhAnh  = thuocDto.HinhAnh,
                    LuuY     = thuocDto.LuuY,
                    LieuDung = thuocDto.LieuDung
                };
                _thuocRepository.Insert(thuoc);
                _unitOfWork.Commit();

                if (thuocDto.MaBenhs != null)
                {
                    foreach (var mabenh in thuocDto.MaBenhs)
                    {
                        var thuocdieutri = new ThuocDieuTri
                        {
                            MaThuoc = thuoc.MaThuoc,
                            MaBenh  = new Guid(mabenh)
                        };
                        _thuocdieutriRepository.Insert(thuocdieutri);
                    }
                    _unitOfWork.Commit();
                }
                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Example #2
0
        public bool Create(BenhDTO benhDto)
        {
            try
            {
                var item = CheckExistsTenbenh(benhDto.TenBenh);
                if (item)
                {
                    return(false);
                }
                var benh = new Benh
                {
                    MaBenh      = Guid.NewGuid(),
                    TenBenh     = benhDto.TenBenh,
                    NguyenNhan  = benhDto.NguyenNhan,
                    CachDieuTri = benhDto.CachDieuTri,
                    MoTa        = benhDto.MoTa,
                    HinhAnh     = benhDto.HinhAnh,
                };
                _benhRepository.Insert(benh);
                _unitOfWork.Commit();

                if (benhDto.MaThuocs != null)
                {
                    foreach (var mathuoc in benhDto.MaThuocs)
                    {
                        var thuocdieutri = new ThuocDieuTri
                        {
                            MaBenh  = benh.MaBenh,
                            MaThuoc = new Guid(mathuoc),
                        };
                        _unitOfWork.Commit();
                    }
                }

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
        public bool Update(ThuocDTO thuocDto)
        {
            try
            {
                var thuoc = _thuocRepository.GetById(thuocDto.MaThuoc);
                if (thuoc == null)
                {
                    return(false);
                }
                // Update chi tiet
                thuoc.MaThuoc  = thuocDto.MaThuoc;
                thuoc.TenThuoc = thuocDto.TenThuoc.ToLower();
                thuoc.CongDung = thuocDto.CongDung;
                thuoc.CachDung = thuocDto.CachDung;
                thuoc.HinhAnh  = thuocDto.HinhAnh;
                thuoc.LuuY     = thuocDto.LuuY;
                thuoc.LieuDung = thuocDto.LieuDung;
                //update thuốc điều trị
                var thuocdieutriOld = _thuocdieutriRepository.GetMany(p => p.MaThuoc == thuoc.MaThuoc).ToList();
                _thuocdieutriRepository.RemoveMultiple(thuocdieutriOld);

                var benhs = _benhRepository.GetMany(r => thuocDto.MaBenhs.Contains(r.MaBenh.ToString()));
                foreach (var benh in benhs)
                {
                    var thuocdieutri = new ThuocDieuTri {
                        MaBenh = benh.MaBenh, MaThuoc = thuoc.MaThuoc
                    };

                    _thuocdieutriRepository.Insert(thuocdieutri);
                }
                // update user
                _thuocRepository.Update(thuoc);
                _unitOfWork.Commit();
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Example #4
0
        public bool Update(BenhDTO benhDto)
        {
            try
            {
                var benh = _benhRepository.GetById(benhDto.MaBenh);
                if (benh == null)
                {
                    return(false);
                }
                // Update chi tiet
                benh.MaBenh      = benhDto.MaBenh;
                benh.TenBenh     = benhDto.TenBenh.ToLower();
                benh.NguyenNhan  = benhDto.NguyenNhan;
                benh.CachDieuTri = benhDto.CachDieuTri;
                benh.MoTa        = benhDto.MoTa;
                benh.HinhAnh     = benhDto.HinhAnh;

                //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
                _benhRepository.Update(benh);
                _unitOfWork.Commit();
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Example #5
0
        public bool InsertAll(BenhDTO userRoleDataPopups)
        {
            var item = CheckExistsTenbenh(userRoleDataPopups.TenBenh);

            if (item)
            {
                return(false);
            }
            var benh = new Benh
            {
                MaBenh      = Guid.NewGuid(),
                TenBenh     = userRoleDataPopups.TenBenh,
                NguyenNhan  = userRoleDataPopups.NguyenNhan,
                CachDieuTri = userRoleDataPopups.CachDieuTri,
                MoTa        = userRoleDataPopups.MoTa,
                HinhAnh     = userRoleDataPopups.HinhAnh,
            };

            _benhRepository.Insert(benh);
            _unitOfWork.Commit();

            if (userRoleDataPopups.MaThuocs != null)
            {
                foreach (var mathuoc in userRoleDataPopups.MaThuocs)
                {
                    var thuocdieutri = new ThuocDieuTri {
                        MaBenh = benh.MaBenh, MaThuoc = new Guid(mathuoc)
                    };
                    _thuocdieutriRepository.Insert(thuocdieutri);
                }
                _unitOfWork.Commit();
            }


            if (userRoleDataPopups.MaTrieuChungs != null)
            {
                foreach (var matrieuchung in userRoleDataPopups.MaTrieuChungs)
                {
                    var trieuchungbenh = new TrieuChungBenh {
                        MaBenh = benh.MaBenh, MaTrieuChung = new Guid(matrieuchung)
                    };
                    _trieuchungbenhRepository.Insert(trieuchungbenh);
                }
                _unitOfWork.Commit();
            }

            // liệu trình

            //if (userRoleDataPopups.ListLieuTrinhs.Count <= 0)
            //{
            //    return true;
            //}
            ////insert new record
            //for (int i = 0; i < userRoleDataPopups.ListLieuTrinhs.Count; i++)
            //{
            //    var roleViewModel = userRoleDataPopups.ListLieuTrinhs[i];


            //    //if (LieuTrinhConstant.MaLieuTrinh_Empty.Equals(roleViewModel.MaLieuTrinh.ToString()))
            //    //{
            //        roleViewModel.MaBenh = benh.MaBenh;
            //        roleViewModel.MaLieuTrinh = Guid.NewGuid();
            //    //    continue;
            //    //}
            //    var lstLieuTrinhs = _lieutrinhRepository.GetAll()
            //        .Where(p => p.MaLieuTrinh == roleViewModel.MaLieuTrinh && p.MaBenh == roleViewModel.MaBenh).ToList();
            //    LieuTrinh LieuTrinh = null;
            //    switch (lstLieuTrinhs.Count)
            //    {
            //        case 0:
            //            LieuTrinh = new LieuTrinh
            //            {
            //                MaBenh = roleViewModel.MaBenh,
            //                MaLieuTrinh = roleViewModel.MaLieuTrinh,
            //                TenLieuTrinh = roleViewModel.TenLieuTrinh,
            //                MoTaLieuTrinh = roleViewModel.MoTaLieuTrinh
            //            };
            //            _lieutrinhRepository.Insert(LieuTrinh);
            //            break;
            //        default:
            //            LieuTrinh = lstLieuTrinhs[0];

            //            _lieutrinhRepository.Update(LieuTrinh);
            //            break;
            //    }

            //}

            // delete record

            //  DeleteRecord(userId, lstData);
            //  _unitOfWork.Commit();
            return(true);
        }