Exemplo n.º 1
0
        public async Task <IActionResult> Edit(DepartmentInputModel model)
        {
            if (!this.departmentsService.Exists(model.Id))
            {
                return(this.BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(this.RedirectToAction("Error", "Home"));
            }

            EditDepartmentServiceModel serviceModel = new EditDepartmentServiceModel
            {
                Id             = model.Id,
                Name           = model.Name,
                Email          = model.Email,
                Description    = model.Description,
                PhoneNumberIds = (model.PhoneNumberIds == null) ? new int[0] : model.PhoneNumberIds,
            };

            await this.departmentsService.EditAsync(serviceModel);

            return(this.RedirectToAction("Details", "Departments", new { id = serviceModel.Id }));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create(DepartmentInputModel model)
        {
            this.FillUnifiedModel();
            if (!this.ModelState.IsValid)
            {
                return(this.View("Create", this.unifiedModel));
            }

            var phones = new List <PhonesDropdownServiceModel>();

            if (model.PhoneNumberIds != null)
            {
                foreach (int phoneNumberId in model.PhoneNumberIds)
                {
                    phones.Add(new PhonesDropdownServiceModel
                    {
                        Id = phoneNumberId,
                    });
                }
            }

            var department = new CreateDepartmentServiceModel
            {
                Name         = model.Name,
                Email        = model.Email,
                Description  = model.Description,
                PhoneNumbers = phones,
            };

            await this.departmentsService.CreateAsync(department);

            return(this.RedirectToAction("Create"));
        }
Exemplo n.º 3
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));
        }