public async Task <IActionResult> PostCountry([FromBody] CountryCreateModel model) { var command = Mapper.Map <CommandCreateCountry>(model); await Mediator.Send(command); return(Ok()); }
public IActionResult Create([FromForm] CountryCreateModel entity) { if (ModelState.IsValid) { string currentUser = HttpContext?.User?.Identity?.Name; if (!String.IsNullOrEmpty(currentUser)) { try { AuditedEntityMapper <CountryCreateModel> .FillCreateAuditedEntityFields(entity, currentUser); bool statusResult = _countryService.Add(entity); if (statusResult) { return(RedirectToAction(nameof(Index)).WithSuccess(LOCALIZATION_SUCCESS_DEFAULT)); } else { return(RedirectToAction(nameof(Index)).WithError(LOCALIZATION_ERROR_DEFAULT)); } } catch (Exception ex) { _logger.LogError(ex, ex.Message); return(RedirectToAction(nameof(Index)).WithError(ex.Message)); } } else { _logger.LogError(LOCALIZATION_ERROR_USER_MUST_LOGIN); return(NotFound().WithError(LOCALIZATION_ERROR_USER_MUST_LOGIN)); } } return(View(entity).WithWarning(LOCALIZATION_WARNING_INVALID_MODELSTATE)); }
public async Task <IActionResult> PatchCountry([FromBody] CountryCreateModel model, [FromRoute][Required] int id) { var command = Mapper.Map <CommandCountryUpdate>(model); command.Id = id; await Mediator.Send(command); return(Ok()); }
public async Task DeleteState(CountryCreateModel data) { try { long Id = Convert.ToInt64(data.id); await Task.Run(() => ManageState.DeleteState(Id)); } catch (Exception) { throw; } }
public async Task <CountryCreateModel> UpdateCountry(CountryCreateModel data) { try { tblCountry dataCountry = await Task.Run(() => ManageCountry.UpdateCountry(data.ConvertTotblCountry())); return(dataCountry.ConvertToCountry()); } catch (Exception) { throw; } }
public async Task <IHttpActionResult> UpdateCountry(CountryCreateModel model) { try { userId = User.Identity.GetUserId(); Helpers.Helpers.AddBaseProperties(model, "update", userId); return(Ok(await CountryService.UpdateCountry(model))); } catch (Exception) { throw; } }
public static tblCountry ConvertTotblCountry(this CountryCreateModel data) { return(new tblCountry() { ID = Convert.ToInt64(data.id), Code = data.countryCode, Name = data.countryName, IsActive = data.isActive, IsDeleted = data.isDeleted ?? false, CreatedUserID = data.createdUserID, UpdatedUserID = data.updatedUserID, CreatedTimestamp = data.createdTimestamp ?? DateTime.Now, UpdatedTimestamp = data.updatedTimestamp ?? DateTime.Now }); }
public bool Add(CountryCreateModel entity) { if (GetByCountryPath(entity.Path)?.Path?.Length > 0) { throw new Exception("Country path already exist"); } Country country = new Country { Name = entity.Name, Path = entity.Path, Abbreviation = entity.Abbreviation, CreatedBy = entity.CreatedBy, CreatedAt = entity.CreatedAt, ModifiedAt = entity.ModifiedAt, ModifiedBy = entity.ModifiedBy }; return(_repository.Add(country)); }
public static async Task CreateDefaultCountry(IServiceProvider serviceProvider, IConfiguration configuration) { var logger = serviceProvider.GetRequiredService <ILogger <SeedExtension> >(); logger.LogInformation("adding default country"); try { var _countryService = serviceProvider.GetService <ICountryService>(); if (!_countryService.GetAll().Any()) { string countryName = configuration["Country:Name"]; string countryPath = configuration["Country:Path"]; string countryAbbreviation = configuration["Country:Abbreviation"]; CountryCreateModel countryCreateModel = new CountryCreateModel { Name = countryName, Path = countryPath, Abbreviation = countryAbbreviation, CreatedAt = DateTime.Now, ModifiedAt = DateTime.Now, CreatedBy = "seedadmin", ModifiedBy = "seedadmin", }; if (!_countryService.Add(countryCreateModel)) { logger.LogInformation("Country cannot be added ."); throw new Exception("Country cannot be added ."); } } } catch (Exception ex) { logger.LogInformation("Country cannot be added ." + ex.Message); throw new Exception("Country cannot be added ." + ex.Message); } }
public Country Add(CountryCreateModel newCountryModel) { return(_countryRepo.Create(newCountryModel.Name)); }