Esempio n. 1
0
        public async Task <IActionResult> Create(CreateDepartmentViewModel model)
        {
            if (ModelState.IsValid)
            {
                var headt = await UserManager.FindByIdAsync(model.HeadTeacherId);

                var name = model.Name;
                var inst = await(from i in DBContext.Institutions.Include(d => d.Departments) where i.Id.ToString() == model.InstId select i).FirstOrDefaultAsync();
                if (headt != null && !String.IsNullOrWhiteSpace(name))
                {
                    EDepartment dep = new EDepartment()
                    {
                        Name        = name,
                        HeadTeacher = headt
                    };

                    inst.Departments.Add(dep);
                    DBContext.Departments.Add(dep);
                    await DBContext.SaveChangesAsync();

                    return(RedirectToAction("Index", new { InstId = model.InstId }));
                }
            }
            else
            {
                model.AvailableTeachers = await UserManager.GetUsersInRoleAsync("Teacher");
            }
            return(View(model));
        }
        public IActionResult Create(string routeString, int routeId)
        {
            CreateDepartmentViewModel model = new CreateDepartmentViewModel();

            model.LoadData(routeString, routeId);
            return(View(model));
        }
Esempio n. 3
0
        public async Task <ActionResult> Create(CreateDepartmentViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Department department = new Department
                    {
                        Name         = model.Name,
                        Budget       = model.Budget,
                        StartDate    = model.StartDate,
                        InstructorID = model.InstructorID
                    };

                    db.Departments.Add(department);
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
            }
            catch (RetryLimitExceededException /* dex */)
            {
                //Log the error (uncomment dex variable name and add a line here to write a log.
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
            }

            ViewBag.InstructorID = new SelectList(db.Instructors, "ID", "FullName", model.InstructorID);
            return(View(model));
        }
Esempio n. 4
0
        public async Task <HttpResponseMessage> CreateAsync(CreateDepartmentViewModel createDepartmentViewModel)
        {
            createDepartmentViewModel.ThrowIfNull(nameof(createDepartmentViewModel));

            HttpResponseMessage response = await _httpClient.PostAsJsonAsync("v1/departments", createDepartmentViewModel);

            return(response);
        }
        // GET: Admin/CreateDepartment
        public ActionResult CreateDepartment()
        {
            List <ApplicationUser>    users            = db.GetAllUsers().ToList();
            CreateDepartmentViewModel createDepartment = new CreateDepartmentViewModel {
                Users = users
            };

            createDepartment.UserNames = db.GetAllUserNames().ToList();
            return(View(createDepartment));
        }
        public async Task CreateDepartmentAsync(CreateDepartmentViewModel createDepartmentViewModel)
        {
            string jsonStringBody = JsonSerializer.Serialize(createDepartmentViewModel);

            using StringContent stringContent = new StringContent(jsonStringBody, Encoding.UTF8, "application/json");
            HttpResponseMessage response = await _httpClient.PostAsync("department/create-department", stringContent);

            if (!response.IsSuccessStatusCode)
            {
                throw new ApplicationException($"{response.ReasonPhrase}: The status code is: {(int)response.StatusCode}");
            }
        }
Esempio n. 7
0
        public async Task <IActionResult> Create(string InstId)
        {
            var id = InstId;
            CreateDepartmentViewModel model = new CreateDepartmentViewModel()
            {
                AvailableTeachers = await UserManager.GetUsersInRoleAsync("Teacher"),
                InstId            = id,
                userGrants        = await checkService.getUserGrants(User)
            };

            return(View(model));
        }
Esempio n. 8
0
        public ActionResult Create(CreateDepartmentViewModel department)
        {
            try
            {
                // TODO: Add insert logic here

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Esempio n. 9
0
        public ActionResult Create(CreateDepartmentViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                Department department = new Department();
                department = mapper.Map <Department>(viewModel);
                repository.Add(department);
                repository.Save();

                return(RedirectToAction("index", "Department"));
            }

            return(View(viewModel));
        }
        public IActionResult Update([FromBody] CreateDepartmentViewModel model)
        {
            if (_departmentService.Update(model.DepartmentId, model.DepartmentName, out string message))
            {
                apiResponse.ResponseCode    = "00";
                apiResponse.ResponseMessage = "SUCCESS!";
            }
            else
            {
                apiResponse.ResponseCode    = "-01";
                apiResponse.ResponseMessage = message;
            }

            return(new JsonResult(apiResponse));
        }
 public ActionResult AddDepartment(CreateDepartmentViewModel model)
 {
     if (ModelState.IsValid)
     {
         var department = new Department()
         {
             Name      = model.Name,
             ManagerId = model.ManagerId ?? default(int)
         };
         unitOfWork.DepartmentRepository.Add(department);
         unitOfWork.Complete();
     }
     ViewBag.AvailableManagers = unitOfWork.EmployeeRepository.Find(x => x.Department == null, new string[0]).ToList();
     return(View(model));
 }
Esempio n. 12
0
        public async Task <IActionResult> CreateDepartment()
        {
            var countries = _mapper.Map <List <CountryViewModel> >(await _nomenclatureService.GetCountries());
            var companies = _mapper.Map <List <CompanyViewModel> >(await _adminService.GetCompanies());

            var model = new CreateDepartmentViewModel
            {
                Cities    = _mapper.Map <List <CityViewModel> >(await _nomenclatureService.GetCitiesByCountryId(countries[0].Id)),
                Countries = countries,
                Companies = companies
            };


            return(View(model));
        }
Esempio n. 13
0
        public async Task <IActionResult> CreateDepartment(CreateDepartmentViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var createModel = _mapper.Map <DepartmentServiceModel>(model);

            createModel.Location.City = await _nomenclatureService.GetCity(model.CityId);

            createModel.Company = await _adminService.GetCompany(model.CompanyId);

            await _adminService.CreateDepartment(createModel);

            return(RedirectToAction(nameof(Departments)));
        }
        public IActionResult Create(CreateDepartmentViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _unitOfWork.Departments.Add(model.Department);
                    _unitOfWork.Departments.Add(model.Department);
                    _unitOfWork.Save();
                    model.Success = true;
                }
                catch (ValidationException ex)
                {
                    model.Error = true;
                }
            }

            return(View(model));
        }
        public ActionResult CreateDepartment(CreateDepartmentViewModel createDepartment)
        {
            List <ApplicationUser> users = db.GetAllUsers().ToList();

            createDepartment.Users     = users;
            createDepartment.UserNames = db.GetAllUserNames().ToList();

            createDepartment.Manager = db.GetAllUsers().Where(u => u.UserName == createDepartment.ManagerUserName).First();
            if (ModelState.IsValid)
            {
                Department department = new Department {
                    Manager = createDepartment.Manager, Name = createDepartment.Name
                };
                db.AddDepartment(department);

                return(RedirectToAction("Index"));
            }

            return(View(createDepartment));
        }
Esempio n. 16
0
        public async Task <IActionResult> Create(CreateDepartmentViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }
            var user = await this.userManager.GetUserAsync(this.User);

            var companyId = this.departmentService.GetCompanyIdByDepartmentId(user.DepartmentId);

            if (this.departmentService.CheckIfDepartmentExist(model.Tittle, companyId))
            {
                this.ModelState.AddModelError(string.Empty, GlobalConstant.DepartmentExistErrorMsg);

                return(this.View(model));
            }

            await this.departmentService.CreateAsync(model.Tittle, companyId, user.CityId);

            return(this.RedirectToAction("Index"));
        }
Esempio n. 17
0
        // GET: Department/Create
        public ActionResult Create()
        {
            var instructors = _instructorService.GetAllInstructors()
                              .Select(n => new SelectListItem
            {
                Text = n.FullName, Value = n.Id.ToString()
            }).ToList();

            instructors.Insert(0,
                               new SelectListItem {
                Value = null, Text = @"--- select Instructor ---"
            });

            var departmentCreate = new CreateDepartmentViewModel
            {
                Instructors = instructors
            };


            return(View(departmentCreate));
        }
Esempio n. 18
0
        public ActionResult Create()
        {
            var instructors = _instructorService.GetAllInstructors().Select(n => new SelectListItem
            {
                Text  = n.FirstName + " " + n.LastName,
                Value = n.Id.ToString()
            }).ToList();

            instructors.Insert(0,
                               new SelectListItem
            {
                Value = null,
                Text  = @"--- select Instructor ---"
            });
            // this departmentCreate variable only contains instructor data, all other properties are null
            // thus we need to pass those properties to this variable
            var departmentCreate = new CreateDepartmentViewModel
            {
                Instructors = instructors
            };

            return(View(departmentCreate));
        }
Esempio n. 19
0
        public ActionResult Create(CreateDepartmentViewModel department)
        {
            //string departname,decimal budget,DateTime startdate,string DEPARTNAME,string DEPTID
            //FormCollection form
            // get the data from the form collection and call service layer
            // save to database

            try
            {
                //var departmentName = form["departname"];
                //var budget = form["budget"];
                //var startDate = form["startdate"];

                //Department department = new Department();
                //department.Name = departname;
                //department.Budget = budget;
                //department.StartDate = startdate;
                //department.InstructorId = 1;
                var newDepartment = new Department
                {
                    Name         = department.Name,
                    Budget       = department.Budget,
                    StartDate    = department.StartDate,
                    InstructorId = department.SelectedInstructorId//why selected instructorid is 0? seems not correspond id passed in?
                };
                _departmentService.CreateDepartment(newDepartment);


                return(RedirectToAction("Index"));
            }
            catch (Exception)
            {
                // return to the same page
                return(View());
            }
        }
Esempio n. 20
0
        public override ActionResult Create()
        {
            var model = new CreateDepartmentViewModel();

            return(View(model));
        }