public bool CreateRegion(RegionCreate model) { Region entity = new Region { LocationInRegion = model.LocationInRegion, RegionName = model.RegionName }; _context.Region.Add(entity); return(_context.SaveChanges() == 1); }
private static string GenerateRegionId(RegionCreate create) { var id = string.Empty; if (!string.IsNullOrEmpty(create.ParentId)) { id += create.ParentId + "/"; } id += create.Name.ToLower().Replace(' ', '-'); return(id); }
public static async Task <Region> CreateRegionAndAssertCreatedAsync( this HttpClient client, RegionCreate create) { var content = new StringContent(JsonConvert.SerializeObject(create), Encoding.UTF8, "application/json"); var response = await client.PostAsync("/regions", content); response.AssertStatusCode(HttpStatusCode.Created); return(await response.DeserializeRegionAsync()); }
public IHttpActionResult Post(RegionCreate region) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateRegionService(); if (!service.CreateRegion(region)) { return(InternalServerError()); } return(Ok()); }
public async Task <IActionResult> InvokeAsync(ActionContext context, RegionCreate create) { RegionEntity parentEntity = null; if (string.IsNullOrEmpty(create.ParentId)) { parentEntity = await _coreDbContext.GetRegionByIdAsync(Constants.RootRegionId); } else { parentEntity = await _coreDbContext.GetRegionByIdAsync(create.ParentId); if (parentEntity == null) { return(BadRequest(context, nameof(RegionCreate.ParentId), "Parent region not found")); } var parentLevel = parentEntity.GetLevel(); if (parentLevel >= 5) { return(BadRequest(context, nameof(RegionCreate.ParentId), "Max level region reached")); } } var entity = _regionMapper.MapToEntity(create); entity.ParentId = parentEntity.Id; var existingEntity = _coreDbContext.GetRegionByIdAsync(entity.Id); if (existingEntity != null) { return(BadRequest( context, $"{nameof(RegionCreate.ParentId)}+{nameof(RegionCreate.Name)}", $"Region with id {entity.Id} already exists")); } await _coreDbContext.Regions.AddAsync(entity); await _coreDbContext.SaveChangesAsync(); return(new CreatedAtActionResult( "Get", "Regions", entity.Id, _regionMapper.MapToResult(entity))); }
// [Authorize(Roles = "Admin")] public bool CreateRegion(RegionCreate model) { var entity = new Region() { OwnerId = _regionId, Name = model.Name, Description = model.Description, }; using (var ctx = new ApplicationDbContext()) { ctx.Regions.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(RegionCreate model) { if (ModelState.IsValid) { return(View(model)); } var service = CreateRegionService(); if (service.CreateRegion(model)) { TempData["SaveResult"] = "Your Region was added."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "The Region could not be added."); return(View(model)); }
public bool CreateRegion(RegionCreate model) { throw new NotImplementedException(); }
public RegionEntity MapToEntity(RegionCreate create) => _mapper.Map <RegionEntity>(create);