public ActionResult Edit(int id) { if (!IsIdentified) { return Redirect("/account/login"); } else { var model = resourceManager.GetResourceById(id); if (model == null || model.UserId != UserInfo.UserId) { return RedirectToAction("Index", "Home"); } else { ResourceViewModel resource = new ResourceViewModel(); resource.ResId = model.Id.ToString(); resource.ResType = model.ResourceType.ToString(); resource.Title = model.Title; resource.CanFriendlyLink = model.CanFriendlyLink; resource.ddlProvince = model.ProvinceId; resource.ddlCity = model.CityId; resource.ddlArea = model.AreaId; resource.SpaceSizeId = model.SpaceSizeId.ToString(); //resource.ShortDesc = model.Description == null ? null : Witbird.SHTS.Common.Html.HtmlUtil.RemoveHTMLTags(model.Description); resource.Description = model.Description; resource.SpacePeopleId = model.SpacePeopleId.ToString(); resource.SpaceTreat = model.SpaceTreat.ToString(); resource.Contact = model.Contract; resource.Email = model.Email; resource.DetailAddress = model.DetailAddress; resource.QQ = model.QQ; resource.Telephone = model.Telephone; resource.Mobile = model.Mobile; resource.WeChat = model.WeChat; resource.Href = model.Href; resource.ImageUrls = model.ImageUrls; //resource.LastUpdatedTime = DateTime.Now; //resource.State = (int)ResourceState.Created; //resource.ClickCount = 0; //resource.ClickTime = DateTime.Now; resource.SpaceTypeId = model.SpaceTypeId.ToString(); resource.ActorTypeId = model.ActorTypeId.ToString(); resource.EquipTypeId = model.EquipTypeId.ToString(); resource.OtherTypeId = model.OtherTypeId.ToString(); resource.ActorFromId = model.ActorFromId.ToString(); resource.ActorSex = model.ActorSex.ToString(); List<int> spacefacilities = new List<int>(); foreach (var item in Witbird.SHTS.Web.Public.MiscData.SpaceFacilityList) { if ((model.SpaceFacilityValue & (int)Math.Pow(2, item.Id - 1)) > 0) { spacefacilities.Add(item.Id); } } resource.SpaceFacilities = string.Join(",", spacefacilities); List<int> spacefeatures = new List<int>(); foreach (var item in Witbird.SHTS.Web.Public.MiscData.SpaceFeatureList) { if ((model.SpaceFeatureValue & (int)Math.Pow(2, item.Id - 1)) > 0) { spacefeatures.Add(item.Id); } } resource.SpaceFeatures = string.Join(",", spacefeatures); return View("Edit", resource); } } }
public ActionResult Edit(ResourceViewModel model) { if (!IsIdentified) { return Redirect("/account/login"); } else { if (ModelState.IsValid) { int id = int.Parse(model.ResId); var resource = resourceManager.GetResourceById(id); if (resource.UserId != UserInfo.UserId) { return Redirect("/"); } else { resource.ResourceType = int.Parse(model.ResType); //resource.UserId = UserInfo.UserId; resource.Title = model.Title; resource.CanFriendlyLink = model.CanFriendlyLink; resource.ProvinceId = model.ddlProvince; resource.CityId = model.ddlCity; resource.AreaId = model.ddlArea; resource.CreateTime = DateTime.Now; resource.SpaceSizeId = string.IsNullOrEmpty(model.SpaceSizeId) ? 0 : int.Parse(model.SpaceSizeId); resource.ShortDesc = model.Description == null ? null : Witbird.SHTS.Common.Html.HtmlUtil.RemoveHTMLTags(model.Description); resource.Description = model.Description; resource.SpacePeopleId = string.IsNullOrEmpty(model.SpacePeopleId) ? 0 : int.Parse(model.SpacePeopleId); resource.SpaceTreat = string.IsNullOrEmpty(model.SpaceTreat) ? 0 : int.Parse(model.SpaceTreat); resource.Contract = model.Contact; resource.Email = model.Email; resource.DetailAddress = model.DetailAddress; resource.QQ = model.QQ; resource.Telephone = model.Telephone; resource.Mobile = model.Mobile; resource.WeChat = model.WeChat; resource.Href = model.Href; resource.ImageUrls = model.ImageUrls; resource.LastUpdatedTime = DateTime.Now; resource.State = (int)ResourceState.Created; resource.ClickCount = 0; resource.ClickTime = DateTime.Now; resource.UserName = UserInfo.UserName; resource.ActorFromId = string.IsNullOrEmpty(model.ActorFromId) ? 0 : int.Parse(model.ActorFromId); resource.ActorSex = string.IsNullOrEmpty(model.ActorSex) ? 0 : int.Parse(model.ActorSex); if (!string.IsNullOrEmpty(model.SpaceFacilities)) { int facilityvalue = 0; var facilities = model.SpaceFacilities.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Distinct().Select(v => int.Parse(v)).ToList(); foreach (var item in facilities) { facilityvalue |= (int)Math.Pow(2, item - 1); } resource.SpaceFacilityValue = facilityvalue; } else { resource.SpaceFacilityValue = 0; } if (!string.IsNullOrEmpty(model.SpaceFeatures)) { int featurevalue = 0; var features = model.SpaceFeatures.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Distinct().Select(v => int.Parse(v)).ToList(); foreach (var item in features) { featurevalue |= (int)Math.Pow(2, item - 1); } resource.SpaceFeatureValue = featurevalue; } else { resource.SpaceFeatureValue = 0; } if (resource.ShortDesc != null && resource.ShortDesc.Length > 150) { resource.ShortDesc = resource.ShortDesc.Substring(0, 147) + "..."; } resource.SpaceTypeId = string.IsNullOrEmpty(model.SpaceTypeId) ? 0 : int.Parse(model.SpaceTypeId); resource.ActorTypeId = string.IsNullOrEmpty(model.ActorTypeId) ? 0 : int.Parse(model.ActorTypeId); resource.EquipTypeId = string.IsNullOrEmpty(model.EquipTypeId) ? 0 : int.Parse(model.EquipTypeId); resource.OtherTypeId = string.IsNullOrEmpty(model.OtherTypeId) ? 0 : int.Parse(model.OtherTypeId); resourceManager.EditResource(resource); return RedirectToAction("my"); } } return View(model); } }
public ActionResult Create() { if (!IsIdentified) { return Redirect("/account/login"); } else { ResourceViewModel spaceViewModel = new ResourceViewModel(); return View("Create", spaceViewModel); } }