Пример #1
0
        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"));
            }
        }
Пример #2
0
        public async Task <IActionResult> Create(PropertyViewModel property)
        {
            if (ModelState.IsValid)
            {
                await _propertyService.AddAsync(property);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(property));
        }
Пример #3
0
        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
            });
        }
Пример #4
0
 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));
        }
Пример #6
0
        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));
        }
Пример #7
0
        public async Task <IActionResult> Post([FromBody] AddEditPropertyRequestModel model)
        {
            var id = await _service.AddAsync(UserInfo.AgencyId, model);

            return(Created(Url.RouteUrl(id), id));
        }