Example #1
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; }
        }
Example #2
0
        public bool postforSoal(SoalVM soalVM, long UserId)
        {
            try
            {
                var(nw, old) = _InsertTags(soalVM);
                var s = old.Union(nw);

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

                _soalRepository.Insert(new Soal
                {
                    Matn = soalVM.Matn,
                    ApplicationUserId = UserId,
                    //ZirReshtehId = 1
                },
                                       w);
                db.SaveAllChanges();
                return(true);
            }
            catch (Exception e) { throw e; }
        }