private Quote GetQuote(int quoteId) { Model.Quote quote = _quoteManager.GetQuote(quoteId); if (quote != null) { var quoteVm = Mapper.Map<Quote>(quote); ClientManager clientManager = new ClientManager(); quoteVm.Clients = Mapper.Map<List<Models.Client.Client>>(clientManager.GetClients()) .OrderBy(i => i.ClientName) .ToList(); if (quoteVm.Awarded) { var pManager = new ProjectManager(); Model.Project associatedProject = pManager.FindAwardedProject(quoteId); if (associatedProject != null) { quoteVm.AssociatedProject = Mapper.Map<Models.Project.Project>(associatedProject); } else { quoteVm.PossibleProjects = Mapper.Map<List<Models.Project.Project>>(pManager.GetProjects(active: true, hasQuote: false)) .OrderByDescending(i => i.ProjectName) .ToList(); } } return quoteVm; } return null; }
public void CreateQuote(string clientName, string description, float estimatedHours, decimal estimatedPrice, string tags, int createdById) { Model.Quote quote = BuildQuote(description, estimatedHours, estimatedPrice, createdById, DateTime.Now); quote.clientname = clientName; BuildTags(tags, quote); DataContext.Quotes.Add(quote); DataContext.SaveChanges(); }
public void AwardQuote(int quoteId) { Model.Quote quote = GetQuote(quoteId); if (quote == null) { return; } quote.awarded = true; quote.awardedDate = DateTime.Now; DataContext.SaveChanges(); }
private void BuildTags(string tags, Model.Quote quote) { if (!string.IsNullOrEmpty(tags)) { var tagList = tags.Split(','); foreach (string tag in tagList) { DataContext.QuoteTags.Add(new Model.QuoteTag { title = tag, quote = quote }); } } }
public void Delete(int quoteId) { Model.Quote quote = GetQuote(quoteId); if (quote == null) { return; } var associatedProject = DataContext.Projects.Where(i => i.quoteid == quote.quoteid).FirstOrDefault(); if (associatedProject != null) { associatedProject.quoteid = null; } DataContext.Quotes.Remove(quote); DataContext.SaveChanges(); }
public void UnAwardQuote(int quoteId) { Model.Quote quote = GetQuote(quoteId); if (quote == null) { return; } quote.awarded = false; quote.awardedDate = null; var associatedProject = DataContext.Projects.Where(i => i.quoteid == quote.quoteid).FirstOrDefault(); if (associatedProject != null) { associatedProject.quoteid = null; } DataContext.SaveChanges(); }
public void Update(int quoteId, string clientName, string description, float estimatedHours, decimal estimatedPrice, string tags) { Model.Quote quote = GetQuote(quoteId); if (quote == null) { return; } quote.clientid = null; quote.clientname = clientName; quote.description = description; quote.hours = estimatedHours; quote.price = estimatedPrice; quote.lastupdateddate = DateTime.Now; DataContext.QuoteTags.RemoveRange(quote.quotetags); BuildTags(tags, quote); DataContext.SaveChanges(); }
public static void AddQuote(Model.Quote quote) { var url = MongoLabSettings.MONGOLAB_API + "databases/alckiebot/collections/quotes?apiKey=" + MongoLabSettings.MongoLabAPIKey; var insertRequest = WebRequest.Create(url); insertRequest.ContentType = "application/json"; insertRequest.Method = "POST"; var insertBodyData = JsonConvert.SerializeObject(new List <Model.Quote> { quote }); using (var streamWriter = new StreamWriter(insertRequest.GetRequestStream())) { streamWriter.Write(insertBodyData); streamWriter.Flush(); streamWriter.Close(); } var insertResponse = (HttpWebResponse)insertRequest.GetResponse(); }
void IKeyword.Process(MessageInfo message) { string response = string.Empty; Match match = quoteRegex.Match(message.Content); if (match.Success) { string attribution = match.Groups["attribution"].Value; string quoteText = match.Groups["text"].Value; DateTime attributionDate = DateTime.Now; //match nicknames NicknameRegex nickMatch = nicknameRegex.FirstOrDefault(n => n.Regex.IsMatch(attribution)); if (nickMatch != null) { attribution = nickMatch.Nickname.Username; } Model.Quote quote = new Model.Quote { Text = quoteText, AttributedTo = attribution, AttributedDate = DateTime.Now, //TODO: parse this from regex CreatedBy = message.Username }; //add to db quoteRepo.AddUpdate(quote); tw.RespondMessage(string.Format("Added new quote: \"{0}\" -{1} {2}" , quoteText , attribution , attributionDate.ToString(DATE_FORMAT, CultureInfo.InvariantCulture))); } }