public Response <Region> AddRegion(AddRegionRequest request) { Response <Region> response = new Response <Region>(); if (request == null || request.Region == null) { ArgumentNullException ex = new ArgumentNullException("AddRegionRequest request"); LogError(ex); response.ErrorCode = ErrorCode.Argument; response.Exception = ex; return(response); } try { RegionAccessor accessor = new RegionAccessor(); response.Result = accessor.AddRegion(request.Region); response.IsSuccess = true; } catch (Exception ex) { LogError(ex); response.IsSuccess = false; response.Exception = ex; response.ErrorCode = ErrorCode.Technical; } return(response); }
public async Task <ActionResult> Create(AddRegionViewModel addRegionVm) { if (!ModelState.IsValid) { Alert("Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } try { // TODO: Add insert logic here var addRegionRequest = new AddRegionRequest { Name = addRegionVm.Name, Description = addRegionVm.Description }; var result = await _regionService.Create(addRegionRequest); if (result.Success) { Alert($"Region Created Successfully", NotificationType.success, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(RedirectToAction(nameof(Index))); } else { Alert($"Error: {result.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } } catch { Alert($"Error Occurred While processing the request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } }
public static int AddRegion(AddRegionRequest request) { Hashtable ht = new Hashtable(); BuildRegionRequest(request, ht); return(Convert.ToInt32(DataSources.Default.ExecuteScalar("AddRegion", null, null, ht))); }
public async Task <ServiceResponse <Region> > Create(AddRegionRequest request) { try { var country = await _countryService.FindByIdInclusive(request.CountryId, x => x.Include(p => p.Regions)); if (!country.Success) { return(new ServiceResponse <Region>($"The country does not exist")); } if (country.Data.Regions.Count > 0 && country.Data.Regions.Any(x => x.Name.ToLower().Equals(request.Name.ToLower()))) { return(new ServiceResponse <Region>($"The region with name {request.Name} already exist exist")); } var region = new Region { Code = $"RGN{_codeGenService.GenerateRandomString(8)}", CountryId = request.CountryId, Name = request.Name, Description = request.Description }; await _regionRepository.Create(region); return(new ServiceResponse <Region>(region)); } catch (Exception ex) { return(new ServiceResponse <Region>($"An Error Occured while creating a region Resource. {ex.Message}")); } }
public async Task <ActionResult> CreateRegion(AddRegionViewModel request) { if (!ModelState.IsValid) { Alert($"Invalid Request.", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(RedirectToAction(nameof(Regions), new { id = request.CountryId })); } try { var addRegionRequest = new AddRegionRequest { CountryId = request.CountryId, Name = request.Name, Description = request.Description }; var result = await _regionService.Create(addRegionRequest); if (!result.Success) { Alert($"{result.Message}", NotificationType.info, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(RedirectToAction(nameof(Regions), new { id = request.CountryId })); } Alert($"Region Created Successfully", NotificationType.success, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(RedirectToAction(nameof(Regions), new { id = request.CountryId })); } catch (Exception ex) { Alert($"Error! {ex.Message}.", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(RedirectToAction(nameof(Regions), new { id = request.CountryId })); } }
public async Task <int> AddRegion(AddRegionRequest request) { var region = new POSSolution.Application.Models.Region { name = request.name, code = request.code, shop = request.shop, createUser = "******", //TODO: Get UserName Login createDate = DateTime.Now, updateDate = DateTime.Now }; _context.Regions.Add(region); return(await _context.SaveChangesAsync()); }
public static int AddRegion(AddRegionRequest request) { return(ConfigDal.AddRegion(request)); }
private static void BuildRegionRequest(AddRegionRequest request, Hashtable ht) { ht.Add("Name", request.Name); ht.Add("ParentId", request.ParentId); ht.Add("SortNumber", request.SortNumber); }
public HttpResponseMessage AddRegion(AddRegionRequest request) { var response = ConfigLogic.AddRegion(request); return(ApiHelper.CreateHttpResponseMessage(response)); }
/// <summary> /// Handles the Click event of the AddRegion control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RoutedEventArgs" /> instance containing the event data.</param> /// <author>Andrew From (fromx010)</author> private void AddRegion_Click(object sender, RoutedEventArgs e) { clearErrorMessages(); //error messages string alreadyExistsInDB = "A Location with that name already exists"; double dRadius; string locationName = txtBoxLocationName.Text; string sLatitude = watcher.Position.Location.Latitude.ToString("0.000"); string sLongitude = watcher.Position.Location.Longitude.ToString("0.000"); double dLatitude = watcher.Position.Location.Latitude; double dLongitude = watcher.Position.Location.Longitude; if (!String.IsNullOrEmpty(txtBoxLocationName.Text)) { if (String.IsNullOrEmpty(txtBoxLocationRadius.Text)) { //Create the locationRegion object for the table GeoAuthLocationRegion newLocationRegion = new GeoAuthLocationRegion { RegionName = locationName, Latitude = dLatitude, Longitude = dLongitude }; if (geoAuthDBView.AddLocationRegion(newLocationRegion)) { //Make the API call GeoAuthApi.AddRegionRequest regionRequest = new AddRegionRequest(); regionRequest.AddRegion(sLatitude, sLongitude, locationName, getCurrentDateTime(), null); //Update the UI on the result regionRequest.AddRegionStatus += (send, evt) => { if (evt.Error == null) { lblErrors.Text = evt.Result; } }; } else { lblErrors.Text = alreadyExistsInDB; } } else if (Double.TryParse(txtBoxLocationRadius.Text, out dRadius)) { //Create the locationRegion object for the table GeoAuthLocationRegion newLocationRegion = new GeoAuthLocationRegion { RegionName = locationName, Latitude = dLatitude, Longitude = dLongitude, Radius = dRadius }; if (geoAuthDBView.AddLocationRegion(newLocationRegion)) { //Make the API call GeoAuthApi.AddRegionRequest regionRequest = new AddRegionRequest(); regionRequest.AddRegion(sLatitude, sLongitude, locationName, getCurrentDateTime(), dRadius.ToString()); //Update the UI on the result regionRequest.AddRegionStatus += (send, evt) => { if (evt.Error == null) { lblErrors.Text = evt.Result; } }; } else { lblErrors.Text = alreadyExistsInDB; } } else { lblErrors.Text = "Could not convert Radius to number"; } } else { lblErrors.Text = "Please enter a name"; } }