Example #1
0
        // GET: /Company/Create

        public void SaveTags(Company ad)
        {
            string s = Request["tags"];

            string[] values = s.Split(',');
            Inspinia_MVC5_SeedProject.Models.Tag[] tags = new Inspinia_MVC5_SeedProject.Models.Tag[values.Length];
            CompanyTag[] qt = new CompanyTag[values.Length];
            for (int i = 0; i < values.Length; i++)
            {
                values[i] = values[i].Trim();
                string ss = values[i];
                if (ss != "")
                {
                    var data = db.Tags.FirstOrDefault(x => x.name.Equals(ss, StringComparison.OrdinalIgnoreCase));

                    tags[i] = new Inspinia_MVC5_SeedProject.Models.Tag();
                    if (data != null)
                    {
                        tags[i].Id = data.Id;
                    }
                    else
                    {
                        tags[i].name      = values[i];
                        tags[i].time      = DateTime.UtcNow;
                        tags[i].createdBy = User.Identity.GetUserId();
                        db.Tags.Add(tags[i]);
                    }
                }
                else
                {
                    tags[i] = null;
                }
            }
            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
                string sb = e.ToString();
            }
            for (int i = 0; i < values.Length; i++)
            {
                if (tags[i] != null)
                {
                    qt[i]           = new CompanyTag();
                    qt[i].companyId = ad.Id;
                    qt[i].tagId     = tags[i].Id;
                    db.CompanyTags.Add(qt[i]);
                }
            }
        }
Example #2
0
        public void SaveQuestionTags(string s, Question q, bool update = false)
        {
            if (update)
            {
                var adid   = q.Id;
                var adtags = db.QuestionTags.Where(x => x.questionId.Equals(adid)).ToList();
                foreach (var cc in adtags)
                {
                    db.QuestionTags.Remove(cc);
                }
                db.SaveChanges();
            }
            string[] values = s.Split(',');
            Inspinia_MVC5_SeedProject.Models.Tag[] tags = new Inspinia_MVC5_SeedProject.Models.Tag[values.Length];
            QuestionTag[] qt = new  QuestionTag[values.Length];
            for (int i = 0; i < values.Length; i++)
            {
                values[i] = values[i].Trim();
                string ss = values[i];
                if (ss != "")
                {
                    var data = db.Tags.FirstOrDefault(x => x.name.Equals(ss, StringComparison.OrdinalIgnoreCase));

                    tags[i] = new Inspinia_MVC5_SeedProject.Models.Tag();
                    if (data != null)
                    {
                        tags[i].Id = data.Id;
                    }
                    else
                    {
                        tags[i].name      = values[i];
                        tags[i].time      = DateTime.UtcNow;
                        tags[i].createdBy = System.Web.HttpContext.Current.User.Identity.GetUserId();
                        db.Tags.Add(tags[i]);
                    }
                }
                else
                {
                    tags[i] = null;
                }
            }
            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
                string sb = e.ToString();
            }
            for (int i = 0; i < values.Length; i++)
            {
                if (tags[i] != null)
                {
                    qt[i]            = new  QuestionTag();
                    qt[i].questionId = q.Id;
                    qt[i].tagId      = tags[i].Id;
                    db.QuestionTags.Add(qt[i]);
                }
            }
            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
                string sb = e.ToString();
            }
        }
        public void SaveTags(string s,ref Ad ad,string addOrUpdate = "add")
        {
            if(addOrUpdate == "update")
            {
                var adid = ad.Id;
                var adtags = db.AdTags.Where(x => x.adId.Equals(adid)).ToList();
                foreach (var cc in adtags)
                {
                    db.AdTags.Remove(cc);
                }
                 db.SaveChanges();
            }
            string[] values = s.Split(',');
            Inspinia_MVC5_SeedProject.Models.Tag[] tags = new Inspinia_MVC5_SeedProject.Models.Tag[values.Length];
            AdTag[] qt = new AdTag[values.Length];
            for (int i = 0; i < values.Length; i++)
            {
                values[i] = values[i].Trim();
                string ss = values[i];
                if (ss != "")
                {
                    var data = db.Tags.FirstOrDefault(x => x.name.Equals(ss, StringComparison.OrdinalIgnoreCase));

                    tags[i] = new Inspinia_MVC5_SeedProject.Models.Tag();
                    if (data != null)
                    {
                        tags[i].Id = data.Id;
                    }
                    else
                    {
                        tags[i].name = values[i];
                        tags[i].time = DateTime.UtcNow;
                        tags[i].createdBy = System.Web.HttpContext.Current.User.Identity.GetUserId();
                        db.Tags.Add(tags[i]);
                    }
                }
                else
                {
                    tags[i] = null;
                }
            }
            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
                string sb = e.ToString();
            }
            for (int i = 0; i < values.Length; i++)
            {
                if (tags[i] != null)
                {
                    qt[i] = new AdTag();
                    qt[i].adId = ad.Id;
                    qt[i].tagId = tags[i].Id;
                    db.AdTags.Add(qt[i]);
                }
            }
            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
                string sb = e.ToString();
            }
        }
Example #4
0
        public ActionResult Create([Bind(Include="Id,category,postedBy,time,title,description")] Question question)
        {
            if (User.Identity.IsAuthenticated) { 
            if (ModelState.IsValid)
            {

                question.time = DateTime.UtcNow;
                question.postedBy = User.Identity.GetUserId();
                db.Questions.Add(question);

                string s = Request["tags"];
                s = s.Trim();
                string[] values = s.Split(',');
                Tag []tags = new Tag[values.Length];
                QuestionTag []qt = new QuestionTag[values.Length];
                //int count = 0;
                for (int i = 0; i < values.Length; i++)
                {
                    values[i] = values[i].Trim();
                    string ss = values[i];
                    if (ss != "")
                    {
                        var data = db.Tags.FirstOrDefault(x => x.name.Equals(ss, StringComparison.OrdinalIgnoreCase));

                        tags[i] = new Tag();
                        if (data != null)
                        {
                            tags[i].Id = data.Id;
                        }
                        else
                        {
                            tags[i].name = values[i];
                            tags[i].time = DateTime.UtcNow;
                            tags[i].createdBy = User.Identity.GetUserId();
                            db.Tags.Add(tags[i]);
                        }
                    }
                    else
                    {
                        tags[i] = null;
                    }
                    

                }


                db.SaveChanges();
                
                for (int i = 0; i < values.Length; i++)
                {
                    qt[i] = new QuestionTag();
                    qt[i].questionId = question.Id;
                    qt[i].tagId = tags[i].Id;
                    db.QuestionTags.Add(qt[i]);
                }

                db.SaveChanges();
                return RedirectToAction("Details", new { id = question.Id, title = ElectronicsController.URLFriendly(question.title) });
            }

            ViewBag.postedBy = new SelectList(db.AspNetUsers, "Id", "Email", question.postedBy);
            return View(question);
            }
            return View(question);
        }
        // GET: /Company/Create
        
        public void SaveTags(Company ad)
        {
            string s = Request["tags"];
            string[] values = s.Split(',');
            Inspinia_MVC5_SeedProject.Models.Tag[] tags = new Inspinia_MVC5_SeedProject.Models.Tag[values.Length];
            CompanyTag[] qt = new CompanyTag[values.Length];
            for (int i = 0; i < values.Length; i++)
            {
                values[i] = values[i].Trim();
                string ss = values[i];
                if (ss != "")
                {
                    var data = db.Tags.FirstOrDefault(x => x.name.Equals(ss, StringComparison.OrdinalIgnoreCase));

                    tags[i] = new Inspinia_MVC5_SeedProject.Models.Tag();
                    if (data != null)
                    {
                        tags[i].Id = data.Id;
                    }
                    else
                    {
                        tags[i].name = values[i];
                        tags[i].time = DateTime.UtcNow;
                        tags[i].createdBy = User.Identity.GetUserId();
                        db.Tags.Add(tags[i]);
                    }
                }
                else
                {
                    tags[i] = null;
                }
            }
            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
                string sb = e.ToString();
            }
            for (int i = 0; i < values.Length; i++)
            {
                if (tags[i] != null)
                {
                    qt[i] = new CompanyTag();
                    qt[i].companyId = ad.Id;
                    qt[i].tagId = tags[i].Id;
                    db.CompanyTags.Add(qt[i]);
                }
            }
        }
Example #6
0
        public async Task<IHttpActionResult> PutTag(int id, Tag tag)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != tag.Id)
            {
                return BadRequest();
            }

            db.Entry(tag).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TagExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
Example #7
0
        public async Task<IHttpActionResult> updateTagAdmin(Tag comment)
        {
            if (User.Identity.IsAuthenticated)
            {
                if (!ModelState.IsValid)
                {
                    return BadRequest();
                }
                var data1 = await db.Tags.FindAsync(comment.Id);

                db.Entry(comment).State = EntityState.Modified;
                await db.SaveChangesAsync();
                return Ok("Done");
            }
            return BadRequest();
        }
Example #8
0
 public async Task<IHttpActionResult> updateTag(Tag comment)
 {
     if (User.Identity.IsAuthenticated)
     {
         if (!ModelState.IsValid)
         {
             return BadRequest();
         }
         var data1 =await db.Tags.FindAsync(comment.Id);
         if (data1.updatedInfo != null)
         {
             return BadRequest("Info is pending Approval");
         }
         int len = comment.info.Length;
         data1.updatedInfo = comment.info;
         data1.updatedTime = DateTime.UtcNow;
         data1.updatedBy = User.Identity.GetUserId();
         //if (isAdmin)
         //{
         //    db.Entry(comment).State = EntityState.Modified;
         //    await db.SaveChangesAsync();
         //    return Ok("Done");
         //}
         try
         {
             db.Entry(data1).State = EntityState.Modified;
         }
         catch (Exception e)
         {
             string s = e.ToString();
         }
         try
         {
             await db.SaveChangesAsync();
         }
         catch (DbEntityValidationException e)
         {
             string s = e.ToString();
             List<string> errorMessages = new List<string>();
             foreach (DbEntityValidationResult validationResult in e.EntityValidationErrors)
             {
                 string entityName = validationResult.Entry.Entity.GetType().Name;
                 foreach (DbValidationError error in validationResult.ValidationErrors)
                 {
                     errorMessages.Add(entityName + "." + error.PropertyName + ": " + error.ErrorMessage);
                 }
             }
         }
         var data = new
         {
             updatedById = data1.updatedBy,
             updatedByName = db.AspNetUsers.Find(data1.updatedBy).Email,
             updatedTime = data1.updatedTime,
             updatedInfo = data1.updatedInfo,
         };
         return Ok(data);
     }
     return BadRequest("Not login");
 }
        public async Task<object> UpdateTags(string s, int companyId)
        {
           var com =await db.Companies.Include("CompanyTags").FirstOrDefaultAsync(x => x.Id.Equals(companyId));
            var temp = com.CompanyTags.ToList();
            foreach (var cc in temp)
            {
                db.CompanyTags.Remove(cc);
            }
            
            await db.SaveChangesAsync();
            if(s == null)
            {
                return -1;
            }
            string[] values = s.Split(',');
            Tag[] tags = new Tag[values.Length];
            CompanyTag[] qt = new CompanyTag[values.Length];
            for (int i = 0; i < values.Length; i++)
            {
                values[i] = values[i].Trim();
                string ss = values[i];
                if (ss != "")
                {
                    var data = await db.Tags.FirstOrDefaultAsync(x => x.name.Equals(ss, StringComparison.OrdinalIgnoreCase));

                    tags[i] = new Tag();
                    if (data != null)
                    {
                        tags[i].Id = data.Id;
                    }
                    else
                    {
                        tags[i].name = values[i];
                        tags[i].time = DateTime.UtcNow;
                        tags[i].createdBy = User.Identity.GetUserId();
                        db.Tags.Add(tags[i]);
                    }
                }
                else
                {
                    tags[i] = null;
                }
            }
            try
            {
                await db.SaveChangesAsync();
            }
            catch (Exception e)
            {
                string sb = e.ToString();
            }
            for (int i = 0; i < values.Length; i++)
            {
                if (tags[i] != null)
                {
                    qt[i] = new CompanyTag();
                    qt[i].companyId = companyId;
                    qt[i].tagId = tags[i].Id;
                    db.CompanyTags.Add(qt[i]);
                }
            }
            await db.SaveChangesAsync();
            var ret = from taa in qt
                      select new
                      {
                          name = taa.Tag.name,
                      };
            return ret;
        }