Ejemplo n.º 1
0
        public async Task EditAsync(CityEditModel cityEdit)
        {
            var original = this.citiesRepository
                           .All()
                           .First(x => x.Id == cityEdit.CityId);

            original.Name = cityEdit.Name;
            await this.citiesRepository.SaveChangesAsync();
        }
Ejemplo n.º 2
0
        public static CityEditModel MapToCityEditModel(City entity)
        {
            var editModel = new CityEditModel();

            editModel.ID       = entity.ID;
            editModel.Name     = entity.Name;
            editModel.Postcode = entity.Postcode;

            return(editModel);
        }
Ejemplo n.º 3
0
        public virtual ActionResult Create(CityEditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var id = _cities.Add(model);

            return(RedirectToAction(MVC.City.Edit(id)));
        }
Ejemplo n.º 4
0
        public virtual ActionResult Edit(long id, CityEditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            _cities.Edit(id, model);

            return(RedirectToAction(MVC.City.Edit(id)));
        }
Ejemplo n.º 5
0
        public async Task <bool> Edit(CityEditModel model)
        {
            var country = await _repository.Filter <City>(x => x.Id == model.Id).FirstOrDefaultAsync();

            if (country == null)
            {
                throw new Exception("Country not found");
            }
            country.Name = model.Name;
            _repository.Update(country);
            await _repository.SaveChangesAsync();

            return(true);
        }
Ejemplo n.º 6
0
        public bool Update(CityEditModel entity)
        {
            City city = _repository.Get(entity.ID);

            if (city == null)
            {
                throw new Exception(LOCALIZATION_GENERAL_NOT_FOUND + entity.ID);
            }

            city.Name     = entity.Name;
            city.Postcode = entity.Postcode;

            city.ModifiedAt = entity.ModifiedAt;
            city.ModifiedBy = entity.ModifiedBy;

            return(_repository.Update(city));
        }
Ejemplo n.º 7
0
        public IActionResult Edit([FromForm] CityEditModel entity)
        {
            if (ModelState.IsValid)
            {
                string currentUser = HttpContext?.User?.Identity?.Name;
                if (!String.IsNullOrEmpty(currentUser))
                {
                    AuditedEntityMapper <CityEditModel> .FillModifyAuditedEntityFields(entity, currentUser);

                    try
                    {
                        _cityService.Update(entity);
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!CityExists(entity.ID))
                        {
                            _logger.LogError(LOCALIZATION_ERROR_NOT_FOUND);
                            return(NotFound().WithError(LOCALIZATION_ERROR_NOT_FOUND));
                        }
                        else
                        {
                            _logger.LogError(LOCALIZATION_ERROR_CONCURENT_EDIT);
                            return(NotFound().WithError(LOCALIZATION_ERROR_CONCURENT_EDIT));
                        }
                    }

                    return(RedirectToAction(nameof(Details), new { id = entity.ID }).WithSuccess(LOCALIZATION_SUCCESS_DEFAULT));
                }
                else
                {
                    _logger.LogError(LOCALIZATION_ERROR_USER_MUST_LOGIN);
                    return(NotFound().WithError(LOCALIZATION_ERROR_USER_MUST_LOGIN));
                }
            }
            return(View(entity).WithWarning(LOCALIZATION_WARNING_INVALID_MODELSTATE));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Put(CityEditModel cityEdit)
        {
            var response     = new Response();
            var exists       = this.citiesService.Exists(x => x.Id == cityEdit.CityId);
            var existsByName = this.citiesService.Exists(x => x.Id != cityEdit.CityId && x.Name == cityEdit.Name);

            if (!this.ModelState.IsValid || existsByName)
            {
                response.Message = "City with that name already exists!";
                return(this.BadRequest(response));
            }

            if (!exists)
            {
                response.Message = "No such city!";
                return(this.NotFound(response));
            }

            await this.citiesService.EditAsync(cityEdit);

            response.Message = "Successfully edited city!";

            return(this.Ok(response));
        }
Ejemplo n.º 9
0
 public void Edit(long id, CityEditModel model)
 {
     _cities.Update(id, model.EnglishName, model.RussianName, model.Position);
 }
Ejemplo n.º 10
0
 public long Add(CityEditModel model)
 {
     return(_cities.Add(model.EnglishName, model.RussianName, model.Position));
 }
Ejemplo n.º 11
0
 public async Task <IActionResult> Edit([FromBody] CityEditModel model)
 {
     return(await MakeActionCallAsync(async() => await _cityService.Edit(model)));
 }
Ejemplo n.º 12
0
        public void Put([FromBody] CityEditModel model)
        {
            AuditedEntityMapper <CityEditModel> .FillModifyAuditedEntityFields(model, HttpContext?.User?.Identity?.Name);

            Ok(_cityService.Update(model));
        }
Ejemplo n.º 13
0
 public EditViewModel(CityEditModel model) : base(model)
 {
 }