public async Task <IActionResult> Create([FromBody] PropertyModel model) { ModelState.Remove("Address.StreetAddress"); if (!ModelState.IsValid) { string msg = $"{_localizer.GetString("InvalidModel").Value} {nameof(PropertyModel)}!<br />{ModelState.GetErrors()}"; Log.Information($"PropertyController/Create/{CurrentUserId}/{CurrentUserUsername} - {msg}"); return(BadRequest(msg)); } try { var userId = this.User.GetUserId(); PropertyModel entity = await _propertyService.AddAsync(model, userId); string msg = $"{_localizer.GetString("Create success").Value}! (Id: {entity.Id})"; Log.Information($"PropertyController/Create/{CurrentUserId}/{CurrentUserUsername} - {msg}"); return(Ok(entity)); } catch (Exception ex) { Log.Error(ex, $"ERROR creating property by user {CurrentUserId}/{CurrentUserUsername}"); return(BadRequest("Error creating property")); } }
public async Task <IActionResult> Create(PropertyViewModel property) { if (ModelState.IsValid) { await _propertyService.AddAsync(property); return(RedirectToAction(nameof(Index))); } return(View(property)); }
public override async Task <AddPropertyResponse> AddProperty(AddPropertyRequest request, ServerCallContext context) { RequestValidatorHelper.EnsureValidity <AddPropertyRequestValidator, AddPropertyRequest>(request); var command = _mapper.Map <AddPropertyRequest, AddPropertyCommand>(request); var resultId = await _propertyService.AddAsync(request.AgencyId, command); return(new AddPropertyResponse { Id = resultId }); }
public async Task <IActionResult> AddAsync(PropertyToAdd propertyToAdd) { try { return(Ok(await _service.AddAsync(propertyToAdd))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task <IActionResult> Create([Bind("Id,Area,Comments,AppUserId,PropertyTypeId, BuildingId")] PropertyViewModel propertyVm) { if (ModelState.IsValid) { var property = mapper.Map <PropertyViewModel, Property>(propertyVm); await propertyService.AddAsync(property, propertyVm.BuildingId); return(RedirectToAction("Index")); } ViewBag.AllUsers = await appUserService.GetAllAppUsersAsync(); ViewBag.AllPropTypes = await propertyTypeService.GetAllPropertyTypesAsync(); ViewBag.AllBuildings = buildingService.GetAllBuildings().Select(x => new { Id = x.Id, Name = $"{x.Id} {x.City} {x.Street} {x.Number}" }); return(View(propertyVm)); }
public async Task <IActionResult> Post([FromForm] AddPropertyRequestModel model) { int?id; var businessModel = _mapper.Map <AddPropertyRequestDto>(model); try { id = await _service.AddAsync(UserInfo.AgencyId, businessModel); } finally { foreach (var item in businessModel.AttachmentsToAdd) { item.Stream.Dispose(); } } return(Created(Url.RouteUrl(id), id)); }
public async Task <IActionResult> Post([FromBody] AddEditPropertyRequestModel model) { var id = await _service.AddAsync(UserInfo.AgencyId, model); return(Created(Url.RouteUrl(id), id)); }