public async Task <IActionResult> Edit(OperatingLocationInputModel model)
        {
            if (!this.operatingLocationsService.Exists(model.Id))
            {
                return(this.BadRequest());
            }

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

            EditOperatingLocationServiceModel serviceModel = new EditOperatingLocationServiceModel
            {
                Id            = model.Id,
                Town          = model.Town,
                Address       = model.Address,
                Description   = model.Description,
                ImageUrl      = model.ImageUrl,
                DepartmentIds = model.DepartmentIds,
            };

            await this.operatingLocationsService.EditAsync(serviceModel);

            return(this.RedirectToAction("Details", "OperatingLocations", new { id = serviceModel.Id }));
        }
        public IActionResult Edit(int id)
        {
            OperatingLocationServiceModel operatingLocation = this.operatingLocationsService.GetById(id);

            if (operatingLocation.Town == null || operatingLocation.Address == null)
            {
                return(this.BadRequest());
            }

            var model = new OperatingLocationInputModel
            {
                Id            = operatingLocation.Id,
                Town          = operatingLocation.Town,
                Address       = operatingLocation.Address,
                Description   = operatingLocation.Description,
                ImageUrl      = operatingLocation.ImageUrl,
                DepartmentIds = operatingLocation.DepartmentIds,
                Departments   = this.departmentsService.GetAll().Select(x => new DepartmentsDropdownViewModel
                {
                    Id     = x.Id,
                    Name   = x.Name,
                    Email  = x.Email,
                    Phones = x.Phones.Select(x => new PhonesDropdownViewModel
                    {
                        Id          = x.Id,
                        PhoneNumber = x.PhoneNumber,
                    })
                }),
            };

            return(this.View(model));
        }
        public async Task <IActionResult> Create(OperatingLocationInputModel model)
        {
            this.FillOperatingLocationInputModel();
            if (!this.ModelState.IsValid)
            {
                return(this.View("Create", this.operatingLocationInputModel));
            }

            var departments       = this.departmentsService.GetAllDepartmentsWithSelectedPhones(model.DepartmentIds);
            var operatingLocation = new CreateOperatingLocationServiceModel
            {
                Town        = model.Town,
                Address     = model.Address,
                Description = model.Description,
                ImageUrl    = model.ImageUrl,
                Departments = departments,
            };

            await this.operatingLocationsService.CreateAsync(operatingLocation);

            return(this.RedirectToAction("Create"));
        }
 //------------- CONSTRUCTORS --------------
 public OperatingLocationsController(IDepartmentsService departmentsService, IOperatingLocationsService operatingLocationsService)
 {
     this.departmentsService          = departmentsService;
     this.operatingLocationsService   = operatingLocationsService;
     this.operatingLocationInputModel = new OperatingLocationInputModel();
 }