Exemplo n.º 1
0
 public static void createUser(String userName, List <int> tags, List <int> gifts)
 {
     using (var context = new GifterDBEntities())
     {
         Users user = new Users();
         user.UserName = userName;
         foreach (int i in tags)
         {
             user.Tags.Add(context.Tags.First(x => x.TagId == i));
         }
         foreach (int i in gifts)
         {
             user.Gifts.Add(context.Gifts.First(x => x.GiftId == i));
         }
         context.Users.Add(user);
         context.SaveChanges();
     }
 }
Exemplo n.º 2
0
        public static List <int> getPresentsFromString(String s)
        {
            String[]   presents   = s.Split(',');
            List <int> presentIds = new List <int>();

            foreach (String s_present in presents)
            {
                String tmp = s_present.Trim();
                using (var context = new GifterDBEntities())
                {
                    Gifts gift = context.Gifts.FirstOrDefault(x => x.GiftName.Equals(tmp));
                    if (gift == null)
                    {
                        gift          = new Gifts();
                        gift.GiftName = tmp;
                        context.Gifts.Add(gift);
                        context.SaveChanges();
                    }
                    presentIds.Add(gift.GiftId);
                }
            }
            return(presentIds);
        }
Exemplo n.º 3
0
        public static List <int> getTagsFromString(String s)
        {
            String[]   tags   = s.Split(',');
            List <int> tagIds = new List <int>();

            foreach (String s_tag in tags)
            {
                String tmp = s_tag.Trim();
                using (var context = new GifterDBEntities())
                {
                    Tags tag = context.Tags.FirstOrDefault(x => x.TagName.Equals(tmp));
                    if (tag == null)
                    {
                        tag         = new Tags();
                        tag.TagName = tmp;
                        context.Tags.Add(tag);
                        context.SaveChanges();
                    }
                    tagIds.Add(tag.TagId);
                }
            }
            return(tagIds);
        }