コード例 #1
0
        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;
        }
コード例 #2
0
        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();
        }
コード例 #3
0
 public void AwardQuote(int quoteId)
 {
     Model.Quote quote = GetQuote(quoteId);
     if (quote == null)
     {
         return;
     }
     quote.awarded     = true;
     quote.awardedDate = DateTime.Now;
     DataContext.SaveChanges();
 }
コード例 #4
0
        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
                    });
                }
            }
        }
コード例 #5
0
        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();
        }
コード例 #6
0
        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();
        }
コード例 #7
0
        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();
        }
コード例 #8
0
        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();
        }
コード例 #9
0
        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)));
            }
        }