public ActionResult GetEditHousePage(string id = "") { //return with a House create dto model //this view is also used a edit house page //it the id is empty then it's create house else is edit //todo wan, create the view //user this model to handle user discovery house info var houseDto = new HouseDiscoverDto(); if (id != "") { Jtext103.OldHouse.Business.Models.House house = MyService.FindOneById(new Guid(id)); houseDto = Mapper.Map <HouseDiscoverDto>(house); ViewBag.Title = "编辑" + houseDto.Name; } else { houseDto.Id = Guid.NewGuid().ToString(); houseDto.OwnerId = AppUser.Id.ToString(); houseDto.IsApproved = "False"; houseDto.Country = "中国"; houseDto.Province = "湖北省"; houseDto.City = "武汉市"; houseDto.Cover = "/Content/Images/components/noImage.jpg"; houseDto.Images = new List <string>(); houseDto.BuiltYear = DateTime.Now.Year; ViewBag.Title = "分享你的城迹"; } return(View(houseDto)); }
public ActionResult AddOrModifyHouse(HouseDiscoverDto newHouse) { //for edit a house,we should Authorize if (!(new Guid(newHouse.OwnerId).Equals(AppUser.Id) || AppUser.Roles.Contains("Editor"))) { Jtext103.Auth.Jtext103AuthMiddleware <Jtext103.OldHouse.Business.Models.OldHouseUser> .Logout(HttpContext.GetOwinContext().Environment); return(RedirectToAction("Login", "Account", new { area = "" })); } if (ModelState.IsValid) { //mapper has bug //var house = Mapper.Map<Jtext103.OldHouse.Business.Models.House>(newHouse); //house.CodeName = newHouse.Name.GeneratePinYinSlug(); //this is not tested yet! may have bugs var house = new Jtext103.OldHouse.Business.Models.House() { Name = newHouse.Name, LocationString = newHouse.LocationString, Country = newHouse.Country, Province = newHouse.Province, City = newHouse.City, Abstarct = newHouse.Abstarct, Description = newHouse.Description, Images = newHouse.Images, Cover = newHouse.Cover, Rating = newHouse.Rating, Id = new Guid(newHouse.Id), OwnerId = new Guid(newHouse.OwnerId), IsApproved = Convert.ToBoolean(newHouse.IsApproved), Location = HouseService.GetGeoPoint(newHouse.Lnt + @";" + newHouse.Lat), CodeName = newHouse.Name.GeneratePinYinSlug(), Tags = (newHouse.Tags == null ? new List <string>() : newHouse.Tags.Split(new string[] { "," }, 100, StringSplitOptions.RemoveEmptyEntries).ToList <string>()) }; house.ModifyExtraInformation("houseinfo-buildyear", new DateTime(newHouse.BuiltYear, 10, 1)); //新建house(数据库中找不到) if (MyService.FindOneById(new Guid(newHouse.Id)) == null) { //产生new house事件 EventService.Publish("NewHouseEvent", house.Id, house.OwnerId); } MyService.SaveOne(house); //todo wan, redirect tho the new house details return(RedirectToAction("HouseDetail", new { id = house.Id })); } if (MyService.FindOneById(new Guid(newHouse.Id)) == null) { ViewBag.Title = "分享你的城迹"; } else { ViewBag.Title = "编辑" + newHouse.Name; } return(View(newHouse)); }