Ejemplo n.º 1
0
        private void EditCountry(string countryName)
        {
            CountryEditViewModel viewModel = new CountryEditViewModel(countryName);
            CountryEditControl   control   = new CountryEditControl(viewModel);
            Window window = WindowFactory.CreateByContentsSize(control);

            viewModel.CountryEdited += (s, e) =>
            {
                CountryEditModel countryEditModel = e.Country;
                CountryEditDTO   countryEditDTO   = Mapper.Map <CountryEditModel, CountryEditDTO>(countryEditModel);

                using (ICountryService service = factory.CreateCountryService())
                {
                    ServiceMessage serviceMessage = service.Update(countryEditDTO);
                    RaiseReceivedMessageEvent(serviceMessage.IsSuccessful, serviceMessage.Message);

                    if (serviceMessage.IsSuccessful)
                    {
                        window.Close();
                        Notify();
                    }
                }
            };

            window.Show();
        }
Ejemplo n.º 2
0
 public void EditCountry(CountryEditModel model)
 {
     using (var httpClient = new HttpClientExtended())
     {
         var dto = AutoMapper.Mapper.Map <PersonalFinanceManager.DTOs.Country.CountryDetails>(model);
         httpClient.Put($"/Country/Edit/{model.Id}", dto);
     }
 }
Ejemplo n.º 3
0
        private void RaiseCountryEditedEvent(CountryEditModel countryEditModel)
        {
            var handler = CountryEdited;

            if (handler != null)
            {
                CountryEditEventArgs e = new CountryEditEventArgs(countryEditModel);
                handler(this, e);
            }
        }
        public ActionResult Edit(CountryEditModel countryEditModel)
        {
            if (ModelState.IsValid)
            {
                _countryService.EditCountry(countryEditModel);

                return(RedirectToAction("Index"));
            }
            return(View(countryEditModel));
        }
Ejemplo n.º 5
0
        public CountryEditModel GetById(int id)
        {
            CountryEditModel result = null;

            using (var httpClient = new HttpClientExtended())
            {
                var response = httpClient.GetSingle <PersonalFinanceManager.DTOs.Country.CountryDetails>($"/Country/Get/{id}");
                result = AutoMapper.Mapper.Map <CountryEditModel>(response);
            }
            return(result);
        }
Ejemplo n.º 6
0
        public virtual ActionResult Create(CountryEditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var id = _countries.Add(model);

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

            _countries.Edit(id, model);

            return(RedirectToAction(MVC.Country.Edit(id)));
        }
Ejemplo n.º 8
0
        public CountryEditViewModel(string oldCountryName)
        {
            countryEditModel = new CountryEditModel
            {
                OldCountryName = oldCountryName,
                NewCountryName = oldCountryName
            };

            this.SaveChangesCommand = new DelegateCommand(() => RaiseCountryEditedEvent(countryEditModel), CanSaveChanges);
            this.UndoCommand        = new DelegateCommand(() => CountryName = countryEditModel.OldCountryName, obj => true);
        }
Ejemplo n.º 9
0
        public static CountryEditModel MapToCountryEditModel(Country entity)
        {
            var editModel = new CountryEditModel();

            editModel.ID           = entity.ID;
            editModel.Name         = entity.Name;
            editModel.Path         = entity.Path;
            editModel.Abbreviation = entity.Abbreviation;

            return(editModel);
        }
Ejemplo n.º 10
0
        public bool Update(CountryEditModel entity)
        {
            if (GetByCountryPath(entity.Path)?.Path?.Length > 0)
            {
                throw new Exception("Country path already exist");
            }

            Country country = _repository.Get(entity.ID);

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

            country.Name         = entity.Name;
            country.Path         = entity.Path;
            country.Abbreviation = entity.Abbreviation;

            country.ModifiedAt = entity.ModifiedAt;
            country.ModifiedBy = entity.ModifiedBy;

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

                    try
                    {
                        _countryService.Update(entity);
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!CountryExists(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.º 12
0
 public void Edit(long id, CountryEditModel model)
 {
     _countries.Update(id, model.EnglishName, model.RussianName, model.Position);
 }
Ejemplo n.º 13
0
 public long Add(CountryEditModel model)
 {
     return(_countries.Add(model.EnglishName, model.RussianName, model.Position));
 }
        /// <summary>
        /// Initialize the Create form.
        /// </summary>
        /// <returns></returns>
        public ActionResult Create()
        {
            var countryEditModel = new CountryEditModel();

            return(View(countryEditModel));
        }
Ejemplo n.º 15
0
 public CountryEditEventArgs(CountryEditModel country)
 {
     this.Country = country;
 }