Example #1
0
        public AttributeType GetAttributeType(string typename, bool typeadd = false)
        {
            AttributeType atype = null;

            using (SystemMapEntities db = new SystemMapEntities())
            {
                atype = db.attribute_types
                        .Where(at => at.name == typename)
                        .Select(at => new AttributeType
                {
                    typeId      = at.attrtypeid,
                    name        = at.name,
                    description = at.descr,
                    iconUrl     = at.iconurl
                })
                        .SingleOrDefault();
                if (atype == null && typeadd && !String.IsNullOrEmpty(typename) && !String.IsNullOrWhiteSpace(typename))
                {
                    attribute_types natype = new attribute_types {
                        name = typename
                    };
                    db.attribute_types.Add(natype);
                    db.SaveChanges();
                    atype = new AttributeType {
                        typeId = natype.attrtypeid, name = typename
                    };
                }
            }
            return(atype);
        }
Example #2
0
 public void DeleteAttributeType(int atypeid)
 {
     using (SystemMapEntities db = new SystemMapEntities())
     {
         attribute_types delrec = db.attribute_types.Where(at => at.attrtypeid == atypeid).SingleOrDefault();
         if (delrec != null)
         {
             db.attribute_types.Remove(delrec);
             db.SaveChanges();
         }
     }
 }
Example #3
0
 public void UpdateAttributeType(AttributeType udata)
 {
     using (SystemMapEntities db = new SystemMapEntities())
     {
         attribute_types utype = db.attribute_types
                                 .Where(at => at.attrtypeid == udata.typeId)
                                 .SingleOrDefault();
         if (utype != null)
         {
             utype.name    = udata.name;
             utype.descr   = udata.description;
             utype.iconurl = udata.iconUrl;
             db.SaveChanges();
         }
     }
 }
Example #4
0
        public AttributeType AddAttributeType(AttributeType atype)
        {
            AttributeType typeval = null;

            using (SystemMapEntities db = new SystemMapEntities())
            {
                //check that we don't already have this name
                int ecount = db.attribute_types.Where(n => n.name == atype.name).Count();
                if (ecount == 0)
                {
                    //Go ahead and add it
                    attribute_types addtype = new attribute_types {
                        name = atype.name, descr = atype.description, iconurl = atype.iconUrl
                    };
                    db.attribute_types.Add(addtype);
                    db.SaveChanges();
                    typeval = new AttributeType {
                        typeId = addtype.attrtypeid, name = addtype.name, description = addtype.descr, iconUrl = addtype.iconurl
                    };
                }
                else
                {
                    typeval = db.attribute_types
                              .Where(n => n.name == atype.name)
                              .Select(n => new AttributeType
                    {
                        typeId      = n.attrtypeid,
                        name        = n.name,
                        description = n.descr,
                        iconUrl     = n.iconurl
                    })
                              .FirstOrDefault();
                }
            }
            return(typeval);
        }