コード例 #1
0
        public async Task <bool> Edit(string id, DepartmentServiceModel departmentServiceModel)
        {
            Hospital hospitalFromDb =
                await GetHospital(departmentServiceModel);

            if (hospitalFromDb == null)
            {
                throw new ArgumentNullException(nameof(hospitalFromDb));
            }

            Department departmentFromDb = await context.Departments.SingleOrDefaultAsync(department => department.Id == id);

            if (departmentFromDb == null)
            {
                throw new ArgumentNullException(nameof(departmentFromDb));
            }

            departmentFromDb.Name        = departmentServiceModel.Name;
            departmentFromDb.Description = departmentServiceModel.Description;
            departmentFromDb.IsActive    = departmentServiceModel.IsActive;

            departmentFromDb.Hospital = hospitalFromDb;

            context.Departments.Update(departmentFromDb);
            int result = await context.SaveChangesAsync();

            return(result > 0);
        }
コード例 #2
0
        public IActionResult Edit(int id)
        {
            DepartmentServiceModel department = this.departmentsService.GetById(id);

            if (department.Name == null)
            {
                return(this.BadRequest());
            }

            var model = new DepartmentInputModel
            {
                Id          = department.Id,
                Name        = department.Name,
                Email       = department.Email,
                Description = department.Description,

                PhoneNumberIds = department.PhoneNumberIds,
                PhoneNumbers   = this.phonesService.GetAll().Select(x => new PhonesDropdownViewModel
                {
                    Id          = x.Id,
                    PhoneNumber = x.PhoneNumber,
                }),
            };

            return(this.View(model));
        }
コード例 #3
0
        public async Task <IActionResult> Edit(string id, DepartmentEditInputModel departmentEditInputModel)
        {
            if (!ModelState.IsValid)
            {
                await GetAllHospitals();

                return(View(departmentEditInputModel));
            }

            DepartmentServiceModel departmentServiceModel = AutoMapper.Mapper.Map <DepartmentServiceModel>(departmentEditInputModel);

            await departmentService.Edit(id, departmentServiceModel);

            return(Redirect("/Administration/Department/All"));
        }
コード例 #4
0
        public async Task <IActionResult> Create(DepartmentCreateInputModel departmentAddInputModel)
        {
            if (!ModelState.IsValid)
            {
                await GetAllHospitals();

                return(View(departmentAddInputModel));
            }

            DepartmentServiceModel departmentServiceModel = AutoMapper.Mapper.Map <DepartmentServiceModel>(departmentAddInputModel);

            await departmentService.Create(departmentServiceModel);

            return(Redirect("/Administration/Department/All"));
        }
コード例 #5
0
        public IActionResult Delete(int id)
        {
            DepartmentServiceModel department = this.departmentsService.GetById(id);

            if (department.Name == null)
            {
                return(this.BadRequest());
            }

            var model = new DeleteDepartmentViewModel
            {
                Id          = department.Id,
                Name        = department.Name,
                Email       = department.Email,
                Description = department.Description,
                //TODO: add phones table on delete view
            };

            return(this.View(model));
        }
コード例 #6
0
        public async Task <bool> CreateDepartment(DepartmentServiceModel model)
        {
            try
            {
                _unitOfWork.BeginTransaction();
                var createModel = _mapper.Map <Department>(model);
                await _unitOfWork.GetRepository <Location>().AddItemAsync(createModel.Location);

                await _unitOfWork.GetRepository <Department>().AddItemAsync(createModel);

                await _unitOfWork.CommitAsync();

                return(true);
            }
            catch
            {
                await _unitOfWork.RollbackAsync();

                throw;
            }
        }
コード例 #7
0
        public async Task <bool> Create(DepartmentServiceModel departmentServiceModel)
        {
            Hospital hospitalFromDb = await GetHospital(departmentServiceModel);

            if (hospitalFromDb == null)
            {
                throw new ArgumentNullException(nameof(hospitalFromDb));
            }

            var departmentFromDb = await context.Departments.SingleOrDefaultAsync(x => x.Name == departmentServiceModel.Name);

            if (departmentFromDb != null)
            {
                departmentFromDb.Name        = departmentServiceModel.Name;
                departmentFromDb.Description = departmentServiceModel.Description;
                departmentFromDb.IsActive    = departmentServiceModel.IsActive;
                departmentFromDb.IsDeleted   = false;
                departmentFromDb.DeletedOn   = null;
                departmentFromDb.Hospital    = hospitalFromDb;

                context.Departments.Update(departmentFromDb);

                int result = await context.SaveChangesAsync();

                return(result > 0);
            }
            else
            {
                Department department = AutoMapper.Mapper.Map <Department>(departmentServiceModel);

                department.Hospital = hospitalFromDb;

                context.Departments.Add(department);

                int result = await context.SaveChangesAsync();

                return(result > 0);
            }
        }
コード例 #8
0
 private async Task <Hospital> GetHospital(DepartmentServiceModel departmentServiceModel)
 {
     return(await context.Hospitals
            .SingleOrDefaultAsync(hospital => hospital.Name == departmentServiceModel.HospitalName));
 }