Esempio 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();
        }
Esempio 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);
     }
 }
        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));
        }
Esempio 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);
        }
Esempio 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)));
        }
Esempio 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)));
        }
        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);
        }
Esempio 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);
        }
Esempio 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));
        }
Esempio 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));
        }
Esempio n. 12
0
 public void Edit(long id, CountryEditModel model)
 {
     _countries.Update(id, model.EnglishName, model.RussianName, model.Position);
 }
Esempio 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));
        }
 public CountryEditEventArgs(CountryEditModel country)
 {
     this.Country = country;
 }