Beispiel #1
0
        private (List <TagVM> newtags, List <TagVM> oldtags) _InsertTags(SoalVM soalVM)
        {
            var q = new List <TagVM>();

            var e = new List <TagVM>();

            foreach (var n in soalVM.Tags.Where(x => x.Id == 0))
            {
                q.Add(new TagVM
                {
                    Onvan = n.name,
                    Id    = n.Id,
                }
                      );
            }
            q = _tagRepository.CreatRange(q).ToList();

            foreach (var n in soalVM.Tags.Where(x => x.Id != 0))
            {
                e.Add(new TagVM
                {
                    Onvan = n.name,
                    Id    = n.Id,
                }
                      );
            }

            //var s = q.Union(e);
            return(q.ToList(), e.ToList());
        }
Beispiel #2
0
        private (List <TagVM> newtags, List <TagVM> oldtags) _InsertTags(IList <userTagVm> tagVm)
        {
            var q = new List <TagVM>();

            var e = new List <TagVM>();

            foreach (var n in tagVm.Where(x => x.Id == 0))
            {
                q.Add(new TagVM
                {
                    Onvan        = n.Name,
                    Id           = n.Id,
                    ZirReshtehId = 1
                }
                      );
            }
            q = _tagRepository.CreatRange(q).ToList();

            foreach (var n in tagVm.Where(x => x.Id != 0))
            {
                e.Add(new TagVM
                {
                    Onvan        = n.Name,
                    Id           = n.Id,
                    ZirReshtehId = 1
                }
                      );
            }

            //var s = q.Union(e);
            return(q.ToList(), e.ToList());
        }
Beispiel #3
0
        public bool postforSoal(SoalVM soalVM, long UserId)
        {
            try
            {
                var q = new List <TagVM>();

                var e = new List <TagVM>();

                foreach (var n in soalVM.Tags.Where(x => x.Id == 0))
                {
                    q.Add(new TagVM
                    {
                        Onvan        = n.name,
                        Id           = n.Id,
                        ZirReshtehId = soalVM.ZirReshtehId
                    }
                          );
                }
                q = _tagRepository.CreatRange(q).ToList();

                foreach (var n in soalVM.Tags.Where(x => x.Id != 0))
                {
                    e.Add(new TagVM
                    {
                        Onvan        = n.name,
                        Id           = n.Id,
                        ZirReshtehId = soalVM.ZirReshtehId
                    }
                          );
                }

                var s = q.Union(e);
                var w = s.Select(c => c.Id).ToArray();

                // q.AddRange(soalVM.Tags.Where(x => x.Id == 0)
                // .Select(c => new TagVM { ZirReshtehId = c.Id }));
                _soalRepository.Insert(new Soal
                {
                    Matn = soalVM.Matn,
                    ApplicationUserId = UserId,
                    ZirReshtehId      = soalVM.ZirReshtehId
                },
                                       w);
                db.SaveAllChanges();
                return(true);
            }
            catch (Exception e) { throw e; }
        }