コード例 #1
0
        public IActionResult AddDepartment(int?id)
        {
            var model = new AddDepartmentViewModel();

            if (id == null)
            {
                model = new AddDepartmentViewModel
                {
                    Department = new Department(),
                    Faculties  = service.GetFaculties()
                };
            }
            else
            {
                model = new AddDepartmentViewModel
                {
                    Department = new Department(),
                    Faculties  = service.GetFaculties()
                };

                ViewBag.DepartmentId   = service.GetDepartments().First(x => x.Id == id).Id;
                ViewBag.DepartmentName = service.GetDepartments().First(x => x.Id == id).Name;
            }
            return(View(model));
        }
        public IActionResult AddDepartment()
        {
            AddDepartmentViewModel model = new AddDepartmentViewModel();

            GetAllFaculties(model);
            return(RedirectToAction("alldepartments", model));
        }
        private AddDepartmentViewModel GetAllFaculties(AddDepartmentViewModel model)
        {
            var faculties = facultyRepo.GetAll();

            foreach (var faculty in faculties)
            {
                model.Faculties.Add(new SelectListItem {
                    Text = faculty.FacultyName, Value = faculty.Id.ToString()
                });
            }
            return(model);
        }
コード例 #4
0
        /// <summary>
        /// Диалоговое окно для добавления департамента
        /// </summary>
        public static Department Show()
        {
            WindowAddDepartament   addDepartment           = new WindowAddDepartament();
            AddDepartmentViewModel addDepartamentViewModel = new AddDepartmentViewModel();

            addDepartamentViewModel.Title   = "Добавить депортамент";
            addDepartamentViewModel.AddText = "Добавить";
            addDepartment.DataContext       = addDepartamentViewModel;

            addDepartment.ShowDialog();

            return(addDepartamentViewModel.Department);
        }
コード例 #5
0
        public async Task <IActionResult> AddDepartment(AddDepartmentViewModel model)
        {
            Result result = new Result();
            string userId = HttpContext.Session.GetString(SessionHelper.USER_ID);

            result = await _maintenanceService.CreateDepartment(_mapper.Map <AddDepartmentDTO>(model), userId);

            //redirect to user list after add
            if (result.Success)
            {
                result.IsRedirect  = true;
                result.RedirectUrl = "Maintenance/Department";
            }
            return(Json(result));
        }
 public IActionResult AddDepartment(AddDepartmentViewModel model)
 {
     if (ModelState.IsValid)
     {
         Department department = new Department
         {
             DepartmentCode = model.DepartmentCode,
             DepartmentName = model.DepartmentName,
             FacultyId      = model.FacultyId
         };
         entityRepository.Insert(department);
         entityRepository.Save();
         return(Redirect("alldepartments"));
     }
     return(View(model));
 }
コード例 #7
0
 public IActionResult AddDepartment(AddDepartmentViewModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var department = _mapper.Map <Department>(model);
             _storeRepository.InsertDepartment(department);
             _unitOfWork.Commit();
         }
         return(RedirectToAction(nameof(this.ManageDepartments)));
     }
     catch
     {
         return(View());
     }
 }
コード例 #8
0
        public async Task <IActionResult> AddDepartment(AddDepartmentViewModel model)
        {
            if (ModelState.IsValid)
            {
                var depFromDb = await context.Departments.Where(d => d.Name == model.Name).FirstOrDefaultAsync();

                if (depFromDb == null)
                {
                    var dep = new Department()
                    {
                        Name        = model.Name,
                        Email       = model.Email,
                        Description = model.Description
                    };

                    await context.Departments.AddAsync(dep);

                    int changesCount = await context.SaveChangesAsync();

                    if (changesCount > 0)
                    {
                        var appLogType = context.AppLogTypes.Where(c => c.TypeName == "DepartmentAdded").FirstOrDefault();

                        var appLog = new AppLog()
                        {
                            Created    = DateTime.Now,
                            AppLogType = appLogType,
                            Message    = $"Добавлен новый отдел. ID: {dep.Id}, Наименование: {dep.Name}"
                        };

                        await context.AppLogs.AddAsync(appLog);

                        await context.SaveChangesAsync();
                    }
                    return(RedirectToAction("Index", "Department"));
                }
                else
                {
                    ModelState.AddModelError("", "Указанный отдел уже присутствует в базе данных. Укажите другой.");
                }
            }
            return(View());
        }
コード例 #9
0
 public void AddDepartment(AddDepartmentViewModel model)
 {
     try
     {
         if (model != null)
         {
             MasterDepartment entity = new MasterDepartment();
             entity.DepartmentName = model.DepartmentName;
             db.MasterDepartments.Add(entity);
         }
         else
         {
             throw new Exception("Department could not be blank!");
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #10
0
        /// <summary>
        /// Диалоговое окно для редактирования департамента
        /// </summary>
        public static Department Show(Department department)
        {
            if (department != null)
            {
                WindowAddDepartament   addDepartment           = new WindowAddDepartament();
                AddDepartmentViewModel addDepartamentViewModel = new AddDepartmentViewModel();

                addDepartamentViewModel.Title           = "Редактировать депортамент";
                addDepartamentViewModel.AddText         = "Изменить";
                addDepartamentViewModel.NameDepartament = department.NameDepartment;
                addDepartment.DataContext = addDepartamentViewModel;

                addDepartment.ShowDialog();

                if (addDepartamentViewModel.Department != null)
                {
                    department.NameDepartment = addDepartamentViewModel.Department.NameDepartment;
                }
            }

            return(department);
        }
コード例 #11
0
 public AddDepartmentView(Department d = null)
 {
     InitializeComponent();
     DataContext = new AddDepartmentViewModel(this, d, ApplicationService.Instance.EventAggregator);
 }
コード例 #12
0
 /// <summary>
 /// Реализация метода Show из интерфейса IAddDepartment
 /// </summary>
 /// <param name="selectDepartment"></param>
 /// <param name="id"></param>
 public void Show(Department selectDepartment, uint id)
 {
     DataContext = new AddDepartmentViewModel(new Department("Департамент", id,
                                                             new ObservableCollection <Department>()), selectDepartment);
     this.ShowDialog();
 }
コード例 #13
0
        public async Task <IActionResult> AddDepartmentAsync([FromBody] AddDepartmentViewModel departmentViewModel)
        {
            var id = await _universityService.AddDepartmentAsync(departmentViewModel).ConfigureAwait(false);

            return(Ok(id));
        }
コード例 #14
0
 public AddDepartmentWindow(ObservableCollection <Node> nodes, Department department)
 {
     InitializeComponent();
     DataContext = new AddDepartmentViewModel(nodes, department);
 }