Beispiel #1
0
        public async Task <ActionResult <PhieuDanhGiasViewModel> > PostPhieuDanhGia(PhieuDanhGiasViewModel phieuDanhGiaView)
        {
            var phieuDanhGia = Mapper.Map <PhieuDanhGiasViewModel, PhieuDanhGia>(phieuDanhGiaView);

            phieuDanhGia.NgayTao = DateTime.Now;

            _context.PhieuDanhGias.Add(phieuDanhGia);

            _context.SaveChanges();

            phieuDanhGia = _context.PhieuDanhGias.Where(x => x.BenhNhanId == phieuDanhGiaView.BenhNhanId && x.BoPhanId == phieuDanhGiaView.BoPhanId)
                           .OrderByDescending(x => x.NgayTao).ToList()[0];

            var chiTietPhieus = Mapper.Map <List <ChiTietPhieuDanhGiaViewModel>, List <ChiTietPhieuDanhGia> >(phieuDanhGiaView.chiTietPhieuDanhs);

            foreach (var item in chiTietPhieus)
            {
                item.PhieuDanhGiaId = phieuDanhGia.Id;
                item.NgayTao        = DateTime.Now;
            }

            _context.ChiTietPhieuDanhGias.AddRange(chiTietPhieus);

            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetPhieuDanhGia", new { id = phieuDanhGia.Id }, phieuDanhGiaView));
        }
Beispiel #2
0
        public ActionResult <object> PostPhanQuyen(CanBoBenhVienViewModel canBo)
        {
            var deleteList = _context.PhanQuyens.Where(x => x.CanBoBenhVienId == canBo.Id).ToList();

            _context.PhanQuyens.RemoveRange(deleteList);
            _context.SaveChanges();


            if (canBo.PhanQuyens.PhanQuyen == true)
            {
                var phan = new PhanQuyen();
                phan.CanBoBenhVienId = canBo.Id;
                phan.QuyenId         = 1;
                _context.PhanQuyens.Add(phan);
                _context.SaveChanges();
            }

            if (canBo.PhanQuyens.QuanLyDanhMuc == true)
            {
                var phan = new PhanQuyen();
                phan.CanBoBenhVienId = canBo.Id;
                phan.QuyenId         = 2;
                _context.PhanQuyens.Add(phan);
                _context.SaveChanges();
            }

            if (canBo.PhanQuyens.BaoCao == true)
            {
                var phan = new PhanQuyen();
                phan.CanBoBenhVienId = canBo.Id;
                phan.QuyenId         = 3;
                _context.PhanQuyens.Add(phan);
                _context.SaveChanges();
            }

            if (canBo.PhanQuyens.CaNhan == true)
            {
                var phan = new PhanQuyen();
                phan.CanBoBenhVienId = canBo.Id;
                phan.QuyenId         = 4;
                _context.PhanQuyens.Add(phan);
                _context.SaveChanges();
            }


            return(Ok());
        }