Exemplo n.º 1
0
        public override void Setup()
        {
            base.Setup();

            // Spin up mock repository and attach to controller
            MockService = new Mock<IDealService>();

            DefaultDeal = new DeepBlue.Models.Entity.Deal(MockService.Object);
            MockService.Setup(x => x.SaveDeal(It.IsAny<DeepBlue.Models.Entity.Deal>()));
        }
Exemplo n.º 2
0
 private IEnumerable<ErrorInfo> Validate(Deal deal)
 {
     IEnumerable<ErrorInfo> errors = ValidationHelper.Validate(deal);
     if (deal.Partner != null) {
         errors = errors.Union(ValidationHelper.Validate(deal.Partner));
     }
     if (deal.Contact1 != null) {
         errors = errors.Union(ValidationHelper.Validate(deal.Contact1));
         foreach (ContactCommunication comm in deal.Contact1.ContactCommunications) {
             errors = errors.Union(ValidationHelper.Validate(comm.Communication));
         }
     }
     return errors;
 }
Exemplo n.º 3
0
 public static List<DeepBlue.Models.Entity.Deal> GetDealsInFund(CookieCollection cookies, int fundId)
 {
     // Deal/FindDeals?fundId=
     List<DeepBlue.Models.Entity.Deal> deals = new List<DeepBlue.Models.Entity.Deal>();
     // Send the request
     string url = HttpWebRequestUtil.GetUrl("Deal/FindDeals?term=&fundId=" + fundId);
     HttpWebResponse response = HttpWebRequestUtil.SendRequest(url, null, false, cookies, false, HttpWebRequestUtil.JsonContentType);
     if (response.StatusCode == System.Net.HttpStatusCode.OK) {
         using (Stream receiveStream = response.GetResponseStream()) {
             // Pipes the stream to a higher level stream reader with the required encoding format.
             using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8)) {
                 string resp = readStream.ReadToEnd();
                 if (!string.IsNullOrEmpty(resp)) {
                     JavaScriptSerializer js = new JavaScriptSerializer();
                     List<AutoCompleteList> jsonFunds = (List<AutoCompleteList>)js.Deserialize(resp, typeof(List<AutoCompleteList>));
                     foreach (AutoCompleteList alist in jsonFunds) {
                         DeepBlue.Models.Entity.Deal deal = new Deal();
                         deal.DealID = alist.id;
                         deal.DealName = alist.value;
                         deals.Add(deal);
                     }
                 }
                 else {
                 }
                 response.Close();
                 readStream.Close();
             }
         }
     }
     return deals;
 }
Exemplo n.º 4
0
        public void SaveDeal(Deal deal)
        {
            using (DeepBlueEntities context = new DeepBlueEntities()) {
                if (deal.DealID == 0) {
                    context.Deals.AddObject(deal);
                }
                else {
                    Deal updateDeal = context.DealsTable.SingleOrDefault(findDeal => findDeal.DealID == deal.DealID);
                    // Define an ObjectStateEntry and EntityKey for the current object.
                    EntityKey key;
                    object originalItem;

                    if (deal.Partner != null) {
                        // Update partner entity
                        originalItem = null;
                        key = default(EntityKey);
                        key = context.CreateEntityKey("Partners", deal.Partner);
                        if (context.TryGetObjectByKey(key, out originalItem)) {
                            context.ApplyCurrentValues(key.EntitySetName, deal.Partner);
                        }
                        else {
                            updateDeal.Partner = new Partner {
                                CreatedBy = deal.Partner.CreatedBy,
                                CreatedDate = deal.Partner.CreatedDate,
                                EntityID = deal.Partner.EntityID,
                                LastUpdatedBy = deal.Partner.LastUpdatedBy,
                                LastUpdatedDate = deal.Partner.LastUpdatedDate,
                                PartnerID = deal.Partner.PartnerID,
                                PartnerName = deal.Partner.PartnerName
                            };
                        }
                    }

                    /* if (deal.Contact != null) {
                        // Update contact entity
                        originalItem = null;
                        key = default(EntityKey);
                        key = context.CreateEntityKey("Contacts", deal.Contact);
                        if (context.TryGetObjectByKey(key, out originalItem)) {
                            context.ApplyCurrentValues(key.EntitySetName, deal.Contact);
                        }
                        else {
                            updateDeal.Contact = new Contact {
                                ContactID = deal.Contact.ContactID,
                                ContactName = deal.Contact.ContactName,
                                CreatedBy = deal.Contact.CreatedBy,
                                CreatedDate = deal.Contact.CreatedDate,
                                Designation = deal.Contact.Designation,
                                EntityID = deal.Contact.EntityID,
                                FirstName = deal.Contact.FirstName,
                                LastName = deal.Contact.LastName,
                                LastUpdatedBy = deal.Contact.LastUpdatedBy,
                                LastUpdatedDate = deal.Contact.LastUpdatedDate,
                                MiddleName = deal.Contact.MiddleName,
                                ReceivesDistributionNotices = deal.Contact.ReceivesDistributionNotices,
                                ReceivesFinancials = deal.Contact.ReceivesFinancials,
                                ReceivesInvestorLetters = deal.Contact.ReceivesInvestorLetters,
                                ReceivesK1 = deal.Contact.ReceivesK1
                            };
                        }
                        // Update contact communication
                        UpdateContactCommunication(context, deal.Contact, updateDeal.Contact);
                    }
                     * */

                    if (deal.Contact1 != null) {
                        // Update seller contact entity
                        originalItem = null;
                        key = default(EntityKey);
                        key = context.CreateEntityKey("Contacts", deal.Contact1);
                        if (context.TryGetObjectByKey(key, out originalItem)) {
                            context.ApplyCurrentValues(key.EntitySetName, deal.Contact1);
                        }
                        else {
                            updateDeal.Contact1 = new Contact {
                                ContactID = deal.Contact1.ContactID,
                                ContactName = deal.Contact1.ContactName,
                                CreatedBy = deal.Contact1.CreatedBy,
                                CreatedDate = deal.Contact1.CreatedDate,
                                Designation = deal.Contact1.Designation,
                                EntityID = deal.Contact1.EntityID,
                                FirstName = deal.Contact1.FirstName,
                                LastName = deal.Contact1.LastName,
                                LastUpdatedBy = deal.Contact1.LastUpdatedBy,
                                LastUpdatedDate = deal.Contact1.LastUpdatedDate,
                                MiddleName = deal.Contact1.MiddleName,
                                ReceivesDistributionNotices = deal.Contact1.ReceivesDistributionNotices,
                                ReceivesFinancials = deal.Contact1.ReceivesFinancials,
                                ReceivesInvestorLetters = deal.Contact1.ReceivesInvestorLetters,
                                ReceivesK1 = deal.Contact1.ReceivesK1
                            };
                        }
                        // Update seller contact communication
                        UpdateContactCommunication(context, deal.Contact1, updateDeal.Contact1);
                    }

                    key = context.CreateEntityKey("Deals", deal);
                    // Get the original item based on the entity key from the context
                    // or from the database.
                    if (context.TryGetObjectByKey(key, out originalItem)) {
                        // Call the ApplyCurrentValues method to apply changes
                        // from the updated item to the original version.
                        context.ApplyCurrentValues(key.EntitySetName, deal);
                    }
                }
                context.SaveChanges();
            }
        }