Пример #1
0
 public Tag AddTagToDB(string tagName, string tagDescription, string userName, smsfeedbackEntities dbContext)
 {
     logger.Info("Call made");
     try
     {
         //don't add the same tag twice (since the Name is not unique)
        //TODO issue if tag is found for another company!!!
        var companies = from u in dbContext.Users where u.UserName == userName select u.Company;
        var companyName = companies.First().Name;
         var tags = from t in dbContext.Tags where t.Name == tagName && t.Company.Name == companyName select t;
         if (tags.Count() == 0)
         {
             var newTag = new Tag() { Name = tagName, Description = tagDescription, CompanyName = companyName };
             dbContext.Tags.Add(newTag);
             dbContext.SaveChanges();
             return newTag;
         }
         else
         {
             return tags.First();
         }
     }
     catch (Exception ex)
     {
         logger.Error("Error in AddTagToDB", ex);
         return null;
     }
 }
Пример #2
0
 public void AddTagToConversation(Tag tag, string convID, smsfeedbackEntities dbContext)
 {
     logger.Info("Call made");
        try
        {
       var conv = dbContext.Conversations.Find(convID);
       if (conv != null)
       {
          var convTag = new SmsFeedback_EFModels.ConversationTag() { ConversationConvId = convID, TagCompanyName = tag.CompanyName, TagName = tag.Name, DateAdded = DateTime.UtcNow };
          conv.ConversationTags.Add(convTag);
          dbContext.SaveChanges();
       }
        }
        catch (Exception ex)
        {
       logger.Error("Error in AddTagToConversation", ex);
        }
 }