Пример #1
0
        public IActionResult Create()
        {
            var model = new LocationCreateViewModel();

            ViewBag.listDept = _departmentService.GetAll();
            ViewBag.listPos  = _positionService.GetAll();
            return(View(model));
        }
 public IActionResult Create(LocationCreateViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     model.Persist(repositoryFactory);
     return(RedirectToAction(actionName: nameof(Index)));
 }
Пример #3
0
        public IActionResult Create(LocationCreateViewModel locationViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(locationViewModel));
            }

            locationViewModel.CreateLocation(context, locationViewModel);

            return(RedirectToAction(nameof(Index)));
        }
Пример #4
0
        public IActionResult Create(LocationCreateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.ResetCategoryList(context);
                return(View(model));
            }

            model.Persist(context);
            return(RedirectToAction(actionName: nameof(Index)));
        }
Пример #5
0
        public async Task <IActionResult> Edit(LocationCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                var location = _locationService.GetById(model.Id);
                if (location == null)
                {
                    return(NotFound());
                }
                location.LocationName  = model.LocationName;
                location.DepartmentId  = model.DepartmentId;
                location.PositionJobId = model.PositionJobId;
                await _locationService.UpdateAsync(location);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
Пример #6
0
        public IActionResult Edit(int id)
        {
            var location = _locationService.GetById(id);

            if (location == null)
            {
                return(NotFound());
            }
            var model = new LocationCreateViewModel
            {
                Id            = location.Id,
                LocationName  = location.LocationName,
                DepartmentId  = location.DepartmentId,
                PositionJobId = location.PositionJobId
            };

            return(View(model));
        }
Пример #7
0
        public async Task <IActionResult> Create(LocationCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                var location = new Location
                {
                    Id            = model.Id,
                    LocationName  = model.LocationName,
                    DepartmentId  = model.DepartmentId,
                    PositionJobId = model.PositionJobId,
                    Status        = true
                };
                await _locationService.CreateAsync(location);

                return(RedirectToAction(nameof(Index)));
            }
            return(View());
        }
Пример #8
0
        public async Task <IActionResult> Create(LocationCreateViewModel vm, IFormFile file)
        {
            if (ModelState.IsValid)
            {
                //check exists - Name = UNQ
                Location existingLocation = _locationService.GetSingle(loc => loc.Name == vm.Name);
                if (existingLocation == null)
                {
                    Location loc = new Location
                    {
                        Name    = vm.Name,
                        Details = vm.Details,
                        Active  = vm.Active,
                        State   = vm.State
                    };
                    //upload the picture to the file system
                    //assign the picture URL to the cat object
                    if (file != null)
                    {
                        //get the file name
                        string fileName = FileNameHelper.GetNameFormated(Path.GetFileName(file.FileName));
                        await _blobService.UploadFileBlobAsync(file, Path.Combine("uploads", User.Identity.Name, fileName));

                        //assign the picture URL to the cat object
                        loc.Picture = User.Identity.Name + "/" + fileName;
                    }

                    //save to db
                    _locationService.Create(loc);
                    //go home
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ViewBag.MyMessage = "Location name exists. Please change the name";
                    return(View(vm));
                }
            }
            else
            {
                return(View(vm));
            }
        }
Пример #9
0
        public async Task <IActionResult> Create([FromBody] LocationCreateViewModel newLocation)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var location = Mapper.Map <Location>(newLocation);
                    await LocationAppService.Create(location);

                    return(Ok());
                }
                catch (Exception ex)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
                }
            }

            return(BadRequest(ModelState));
        }
        public ActionResult Create(LocationCreateViewModel model)
        {
            var selectedCity   = Convert.ToInt16(model.SelectedCity);
            var selectedCounty = Convert.ToInt16(model.SelectedCounty);

            var newLocation = new Location()
            {
                LocationName        = model.LocationName,
                LocationDescription = model.LocationDescription,
                City   = _currentDb.Cities.Where(x => x.Id == selectedCity).FirstOrDefault(),
                County = _currentDb.Counties.Where(x => x.Id == selectedCounty).FirstOrDefault()
            };

            try
            {
                locationRepo.Save(newLocation);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(View());
            }
            return(RedirectToAction("index"));
        }
        public IActionResult Create()
        {
            LocationCreateViewModel locationCreateViewModel = new LocationCreateViewModel();

            return(View(locationCreateViewModel));
        }
Пример #12
0
        public IActionResult Create()
        {
            LocationCreateViewModel model = new LocationCreateViewModel(context);

            return(View(model));
        }
        public IActionResult Create()
        {
            LocationCreateViewModel model = new LocationCreateViewModel(repositoryFactory);

            return(View(model));
        }
        // GET: Location/Create
        public ActionResult Create()
        {
            var model = new LocationCreateViewModel(_currentDb);

            return(View(model));
        }