Beispiel #1
0
        public void checkDtoUtils()
        {
            // try to cast a House into HouseDto type
            House    h    = new House("DTOtest", 4000);
            HouseDto hdto = DtoUtils.ToDto <HouseDto>(h);

            Assert.AreEqual(h.Name, hdto.Name);
            Assert.AreEqual(h.ID, hdto.ID);
            Assert.AreEqual(h.NumberOfUnits, hdto.NumberOfUnits);

            // try to cast a Character into CharacterDto type
            Character    c    = new Character();
            CharacterDto ctdo = DtoUtils.ToDto <CharacterDto>(c);

            Assert.AreEqual(c.Bravoury, ctdo.Bravoury);

            // try to cast a house into CharacterDto type
            House house = new House("Casting", 10);

            house.ID = 122;
            CharacterDto mutated_bastard_house_into_character = DtoUtils.ToDto <CharacterDto>(house);

            // this should be the only matching property
            Assert.AreEqual(house.ID, mutated_bastard_house_into_character.ID);
            // the others CharacterDto properties should be default or null depending on type
            Assert.IsNull(mutated_bastard_house_into_character.LastName);
            Assert.AreEqual(0, mutated_bastard_house_into_character.Bravoury);
        }
        public IHttpActionResult Patch(int id, Delta <HouseDto> houseDto)
        {
            if (houseDto == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            HouseEntity houseEntityToUpdate = _houseRepository.GetSingle(id);

            if (houseEntityToUpdate == null)
            {
                return(NotFound());
            }

            HouseDto existingHouse = _houseMapper.MapToDto(houseEntityToUpdate);

            houseDto.Patch(existingHouse);

            HouseEntity patched = _houseRepository.Update(_houseMapper.MapToEntity(existingHouse));

            return(Ok(_houseMapper.MapToDto(patched)));
        }
        private static HouseBasicUOType BasicCharacteristicts(this HouseDto dto)
        {
            return(new HouseBasicUOType {
                FIASHouseGuid = dto.FiasGuid,
                CulturalHeritageSpecified = true,
                CulturalHeritage = dto.CulturalHeritage,

                UsedYearSpecified = true,
                UsedYear = (short)dto.UsedYear,

                TotalSquareSpecified = true,
                TotalSquare = dto.TotalSquare,

                FloorCount = dto.FloorCount,

                /// ОКТОМ
                OKTMO = new OKTMORefType {
                    code = dto.OKTMO
                },
                OlsonTZ = new nsiRef {
                    Code = dto.OlsonTZ.Code,
                    GUID = dto.OlsonTZ.Guid
                },
                State = new nsiRef {
                    Code = dto.State.Code,
                    GUID = dto.State.Guid
                }
            });
        }
Beispiel #4
0
        public IActionResult Patch(int id, [FromBody] JsonPatchDocument <HouseDto> housePatchDocument)
        {
            if (housePatchDocument == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            HouseEntity houseEntity = _houseRepository.GetSingle(id);

            if (houseEntity == null)
            {
                return(NotFound());
            }

            HouseDto existingHouse = _houseMapper.MapToDto(houseEntity);

            housePatchDocument.ApplyTo(existingHouse, ModelState);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _houseRepository.Update(_houseMapper.MapToEntity(existingHouse));

            return(Ok(existingHouse));
        }
Beispiel #5
0
        public IActionResult Update(int id, [FromBody] HouseDto houseDto)
        {
            if (houseDto == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            HouseEntity houseEntityToUpdate = _houseRepository.GetSingle(id);

            if (houseEntityToUpdate == null)
            {
                return(NotFound());
            }

            houseEntityToUpdate.ZipCode = houseDto.ZipCode;
            houseEntityToUpdate.Street  = houseDto.Street;
            houseEntityToUpdate.City    = houseDto.City;

            _houseRepository.Update(houseEntityToUpdate);

            return(Ok(_houseMapper.MapToDto(houseEntityToUpdate)));
        }
Beispiel #6
0
        public IActionResult Create([FromBody] HouseDto houseDto)
        {
            try
            {
                if (houseDto == null)
                {
                    return(BadRequest());
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                HouseEntity houseEntity = _houseMapper.MapToEntity(houseDto);

                _houseRepository.Add(houseEntity);

                return(CreatedAtRoute("GetSingleHouse", new { id = houseEntity.Id }, _houseMapper.MapToDto(houseEntity)));
            }
            catch (Exception exception)
            {
                //logg exception or do anything with it
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }
Beispiel #7
0
        public IActionResult Update(int id, [FromBody] HouseDto houseDto)
        {
            try
            {
                if (houseDto == null)
                {
                    return(BadRequest());
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                HouseEntity houseEntityToUpdate = _houseRepository.GetSingle(id);

                if (houseEntityToUpdate == null)
                {
                    return(NotFound());
                }

                houseEntityToUpdate.ZipCode = houseDto.ZipCode;
                houseEntityToUpdate.Street  = houseDto.Street;
                houseEntityToUpdate.City    = houseDto.City;

                _houseRepository.Update(houseEntityToUpdate);

                return(Ok(_houseMapper.MapToDto(houseEntityToUpdate)));
            }
            catch (Exception exception)
            {
                //logg exception or do anything with it
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }
Beispiel #8
0
        public IActionResult Put([FromBody] HouseDto house)
        {
            var entity      = mapper.Map <House>(house);
            var editedHouse = houseRepository.Update(entity);
            var result      = mapper.Map <HouseDto>(editedHouse);

            return(Ok(result));
        }
Beispiel #9
0
        public IActionResult Add([FromBody] HouseDto house)
        {
            var entity   = mapper.Map <House>(house);
            var newHouse = houseRepository.Create(entity);
            var result   = mapper.Map <HouseDto>(newHouse);

            return(Ok(result));
        }
Beispiel #10
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task UpdateAsync(HouseDto input)
        {
            var entity = await _houseReposity.GetAsync(input.Id);

            var community = input.MapTo(entity);

            await _houseReposity.UpdateAsync(community);
        }
Beispiel #11
0
        public static bool CheckHouseObj(HouseDto house, out string message)
        {
            message = "";
            //
            string unitno = string.IsNullOrEmpty(house.UnitNo) ? null : house.UnitNo.DecodeField();

            if (unitno != null && unitno.Length > 20)
            {
                message = "请输入房号单元名称字符长度不能大于20";
                return(false);
            }
            //
            //object floorno = jobj["floorno"] == null ? null : jobj.Value<JValue>("floorno").Value;
            //int fno = 0;
            //if (floorno == null || !int.TryParse(floorno.ToString().DecodeField(), out fno))
            //{
            //    message = "请输入起始楼层";
            //    return false;
            //}
            //
            //string housename = jobj["housename"] == null ? null : jobj.Value<string>("housename").DecodeField();
            //if (housename == null)
            //{
            //    message = "请输入房号";
            //    return false;
            //}
            //if (housename.Length > 20)
            //{
            //    message = "请输入房号字符长度不能大于20";
            //    return false;
            //}
            //
            if (!house.FrontCode.HasValue || !StringHelp.CheckInteger(house.FrontCode.Value.ToString().DecodeField()))
            {
                message = "请输入朝向";
                return(false);
            }
            //
            if (house.BuildArea.HasValue && !StringHelp.CheckDecimal(house.BuildArea.Value.ToString().DecodeField()))
            {
                message = "请输入正确的面积格式";
                return(false);
            }
            //
            if (house.HouseTypeCode.HasValue && !StringHelp.CheckInteger(house.HouseTypeCode.Value.ToString().DecodeField()))
            {
                message = "请输入正确的户型";
                return(false);
            }
            //
            if (house.SightCode.HasValue && !StringHelp.CheckInteger(house.SightCode.Value.ToString().DecodeField()))
            {
                message = "请输入景观";
                return(false);
            }
            return(true);
        }
Beispiel #12
0
 public static House FromDto(HouseDto dto)
 {
     return(new House()
     {
         Id = dto.Id,
         Price = dto.Price,
         City = dto.City,
         Agency = new Agency(dto.AgencyId, dto.AgencyName)
     });
 }
        internal static importHouseRSORequestApartmentHouse MapToApartmentHouseRSO(this HouseDto dto, RequestCMD cmd)
        {
            var value = new importHouseRSORequestApartmentHouse();

            switch (cmd)
            {
            default:
                throw new NotImplementedException();
            }
        }
        /// <summary>
        /// 新增或修改
        /// </summary>
        /// <param name="dto">实体</param>
        /// <returns></returns>
        public HouseDto InsertOrUpdate(HouseDto dto)
        {
            if (Get(dto.Id) != null)
            {
                _houseRepository.Delete(dto.Id);
            }
            var house = _houseRepository.InsertOrUpdate(_mapper.Map <House>(dto));

            return(_mapper.Map <HouseDto>(house));
        }
Beispiel #15
0
 public HouseEntity MapToEntity(HouseDto houseDto)
 {
     return(new HouseEntity()
     {
         Id = houseDto.Id,
         ZipCode = houseDto.ZipCode,
         City = houseDto.City,
         Street = houseDto.Street
     });
 }
Beispiel #16
0
        public HttpResponseMessage Put([FromBody] HouseDto houseDto)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Missing values"));
            }
            string result = _houseService.Edit(houseDto);

            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
Beispiel #17
0
        public HttpResponseMessage Get(string censusHouseNumber)
        {
            HouseDto result = _houseService.GetHouseByCHN(censusHouseNumber.Trim().ToLower());

            if (result != null)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, result));
            }
            return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Not a valid census house number"));
        }
Beispiel #18
0
        private static HouseDto GetHouseDto()
        {
            var houseDto = new HouseDto()
            {
                Name  = "Baker Row",
                Id    = new Random().Next(),
                Owner = Guid.NewGuid().ToString()
            };

            return(houseDto);
        }
Beispiel #19
0
 private static BBIT.Domain.Entities.House.House ConvertHouseDtoToHouse(HouseDto houseDto)
 {
     return(new BBIT.Domain.Entities.House.House
     {
         Id = Guid.Parse(houseDto.Id),
         HouseNumber = houseDto.HouseNumber,
         StreetName = houseDto.StreetName,
         City = houseDto.City,
         Country = houseDto.Country,
         PostCode = houseDto.PostCode
     });
 }
Beispiel #20
0
        public virtual IActionResult GetItem([FromBody] int id)
        {
            HouseDto dto = service.GetById(id);

            if (dto == null)
            {
                return(BadRequest());
            }

            HouseModel model = mapper.Map <HouseModel>(dto);

            return(Ok(model));
        }
        /// <inheritdoc />
        public async Task <HouseDto> Create(HouseDto request)
        {
            var domain = _mapper.ToEntity(request);

            using (var db = new ApplicationDbContext())
            {
                var result = await db.Houses.AddAsync(domain);

                await db.SaveChangesAsync();

                return(await ById(result.Entity.Id));
            }
        }
        private static void DeleteHouse()
        {
            HttpClient client = new HttpClient();
            var        item   = new HouseDto()
            {
                City    = "Ankara",
                Street  = "Çankaya",
                ZipCode = 454545
            };
            var response = client.PostAsync(new Uri(baseAddress + "api/house/5"), item, new JsonMediaTypeFormatter()).Result;

            Console.WriteLine(response);
            Console.WriteLine(response.Content.ReadAsStringAsync().Result);
        }
        public IActionResult Create([FromBody] HouseDto houseDto)
        {
            House house          = _mapper.Map <House>(houseDto);
            var   claimsIdentity = this.User.Identity as ClaimsIdentity;
            var   userId         = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
            bool  succes         = Int32.TryParse(userId, out var ownerId);

            if (succes)
            {
                house.OwnerId = ownerId;
            }
            _houseRepository.Insert(house);
            _houseRepository.Save();
            return(Ok());
        }
        private static void CreateHouse()
        {
            HttpClient client = new HttpClient();
            var        item   = new HouseDto()
            {
                City    = "Istanbul",
                Street  = "Pendik",
                ZipCode = 123123
            };
            var response = client.PostAsync(new Uri(baseAddress + "api/house/"),
                                            new ObjectContent(typeof(HouseDto), item, new JsonMediaTypeFormatter())).Result;

            Console.WriteLine(response);
            Console.WriteLine(response.Content.ReadAsStringAsync().Result);
        }
Beispiel #25
0
        public List <HouseDto> GetHouseByBuildingIdAndFloorNo(int buildingId, int cityId, int floorNo)
        {
            List <HouseDto> houseDtos = new List <HouseDto>();
            var             houses    = _unitOfWork.HouseRepository.Get(m => m.BuildingId == buildingId && m.CityID == cityId && m.Valid == 1).ToList();

            houses.ForEach((o) =>
            {
                var unitNo        = o.UnitNo;
                HouseDto houseDto = Mapper.Map <House, HouseDto>(o);
                houseDto.UnitNo   = GetUnitNoByUnitNoStr(unitNo);
                houseDto.HouseNo  = GetHouseNoByUnitNoStr(unitNo);
                houseDtos.Add(houseDto);
            }
                           );
            return(houseDtos);
        }
        public async Task <IHttpActionResult> Put([FromODataUri] string key, HouseDto houseDto, ODataQueryOptions <HouseDto> odataOptions)
        {
            // get a standard DocumentDB client
            await EnsureClientIsConnected();

            // convert the DTO into the Document type
            var houseDoc = JsonConvert.DeserializeObject <HouseDocument>(JsonConvert.SerializeObject(houseDto));

            // DocumentDB Triggers are "opt-in", so opt-in
            var docdbOptions = new RequestOptions();

            docdbOptions.PreTriggerInclude = new List <string> {
                "MaintainHistoryAndTimestamps"
            };

            // DocumentDB ETag checks are "opt-in", so opt-in if requested
            if (odataOptions.IfMatch != null)
            {
                docdbOptions.AccessCondition = new AccessCondition()
                {
                    Type      = AccessConditionType.IfMatch,
                    Condition = (string)odataOptions.IfMatch["ETag"],
                };
            }

            // execute the replace document call safely with retries
            string documentLink = string.Format(documentLinkFormat, key);
            ResourceResponse <Document> replaced = null;

            try
            {
                replaced = await DocumentDbExtensions.ExecuteResultWithRetryAsync(() =>
                                                                                  client.ReplaceDocumentAsync(documentLink, houseDoc, docdbOptions));
            }
            catch (DocumentDbNonRetriableResponse e)
            {
                return(StatusCode((e.InnerException as DocumentClientException).StatusCode ?? HttpStatusCode.InternalServerError));
            }

            // get the resulting document (it is returned above, but in non-typed form - probably should really be using AutoMapper or something like that here)
            var result = await DocumentDbExtensions.ExecuteQueryWithContinuationAndRetryAsync(
                client.CreateDocumentQuery <HouseDto>(collectionLink)
                .Where(x => x.DocumentType == DocumentType.House)
                .Where(x => x.Id == replaced.Resource.Id));

            return(Updated(result.Single()));
        }
        private void ShowHouseEditDialog(HouseDto selectedItem)
        {
            if (SelectedStreet == null)
            {
                return;
            }
            var model = new HouseAdminDialogViewModel(RequestService, SelectedStreet.Id, selectedItem?.Id);
            var view  = new HouseAddOrEditDialog();

            model.SetView(view);
            view.Owner       = Application.Current.MainWindow;
            view.DataContext = model;
            if (view.ShowDialog() == true)
            {
                RefreshHouses(SelectedStreet);
            }
        }
Beispiel #28
0
        public virtual IActionResult UpdateItem([FromBody] HouseModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            HouseDto dto = mapper.Map <HouseDto>(model);

            service.Update(dto);

            return(Ok());
        }
Beispiel #29
0
        public IActionResult Create([FromBody] HouseDto houseDto)
        {
            if (houseDto == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            HouseEntity houseEntity = _houseMapper.MapToEntity(houseDto);

            _houseRepository.Add(houseEntity);

            return(CreatedAtRoute("GetSingleHouse", new { id = houseEntity.Id }, _houseMapper.MapToDto(houseEntity)));
        }
Beispiel #30
0
        public IHttpActionResult Create([FromBody] HouseDto houseDto)
        {
            if (houseDto == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            HouseEntity houseEntity = houseMapper.MapToEntity(houseDto);

            houseRepository.Add(houseEntity);

            return(Ok(houseEntity));
        }