Exemplo n.º 1
0
        public ActionResult CreateResource(ResourceViewModel model)
        {
            if (!IsIdentified)
            {
                return Redirect("/account/login");
            }
            else
            {
                if (ModelState.IsValid)
                {
                    Witbird.SHTS.DAL.New.Resource resource = new Witbird.SHTS.DAL.New.Resource();

                    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) ? 1 : 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) ? 1 : int.Parse(model.SpacePeopleId);
                    resource.SpaceTreat = 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) ? 1 : int.Parse(model.ActorFromId);
                    resource.ActorSex = string.IsNullOrEmpty(model.ActorSex) ? 1 : int.Parse(model.ActorSex);

                    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);

                    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;
                    }

                    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;
                    }

                    if (resource.ShortDesc != null && resource.ShortDesc.Length > 150)
                    {
                        resource.ShortDesc = resource.ShortDesc.Substring(0, 147) + "...";
                    }

                    resourceManager.CreateResource(resource);

                    return RedirectToAction("my");
                }
                return View(model);
            }
        }
Exemplo n.º 2
0
        public void CreateResource(Resource resource)
        {
            resource.State = 1;
            context.Resources.InsertOnSubmit(resource);

            context.SubmitChanges();
        }
Exemplo n.º 3
0
 public void EditResource(Resource resource)
 {
     var res = context.Resources.SingleOrDefault(v => v.Id == resource.Id);
     if (res != null)
     {
         res.CanFriendlyLink = resource.CanFriendlyLink;
         res.ActorTypeId = resource.ActorTypeId;
         res.EquipTypeId = resource.EquipTypeId;
         res.OtherTypeId = resource.OtherTypeId;
         res.ResourceType = resource.ResourceType;
         res.SpaceFacilityValue = resource.SpaceFacilityValue;
         res.SpaceFeatureValue = resource.SpaceFeatureValue;
         res.SpacePeopleId = resource.SpacePeopleId;
         res.SpaceSizeId = resource.SpaceSizeId;
         res.SpaceTreat = resource.SpaceTreat;
         res.SpaceTypeId = resource.SpaceTypeId;
         res.State = 1;
         res.AreaId = resource.AreaId;
         res.CityId = resource.CityId;
         res.Contract = resource.Contract;
         res.Description = resource.Description;
         res.DetailAddress = resource.DetailAddress;
         res.Email = resource.Email;
         res.Href = resource.Href;
         res.ImageUrls = resource.ImageUrls;
         res.Mobile = resource.Mobile;
         res.ProvinceId = resource.ProvinceId;
         res.QQ = resource.QQ;
         res.ShortDesc = resource.ShortDesc;
         res.Telephone = resource.Telephone;
         res.Title = resource.Title;
         res.WeChat = resource.WeChat;
         res.LastUpdatedTime = DateTime.Now;
         res.EndDate = resource.EndDate;
         res.StartDate = resource.StartDate;
     }
     context.SubmitChanges();
 }
Exemplo n.º 4
0
 partial void DeleteResource(Resource instance);
Exemplo n.º 5
0
 partial void UpdateResource(Resource instance);
Exemplo n.º 6
0
 partial void InsertResource(Resource instance);