示例#1
0
        public static Contact ConvertToDbContact(this ContactModel model)
        {
            var factory = new DatabaseFactory();
            var contactBusinessLogic = new ContactBusinessLogic(new ContactRepository(factory), new DictionaryBusinessLogic<ContactType>(new DictionaryRepository<ContactType>(factory)),
                new DictionaryBusinessLogic<ContactStatus>(new DictionaryRepository<ContactStatus>(factory)), new DictionaryBusinessLogic<AgeDirection>(new DictionaryRepository<AgeDirection>(factory)),
                new DictionaryBusinessLogic<ReadyToSellState>(new DictionaryRepository<ReadyToSellState>(factory)));

            var dbContact = contactBusinessLogic.GetById(model.Id);
            if (dbContact == null)
            {
                dbContact = new Contact();
            }
            dbContact.Age = contactBusinessLogic.GetAllAges().First(x => x.Id == model.AgeDirectionId);
            dbContact.BirthDate = model.BirthDate;
            dbContact.Comment = model.Comment;
            dbContact.CreateDate = DateTime.Now;
            dbContact.Email = model.Email;
            dbContact.Ip = model.ContactIp;
            dbContact.Gender = (GenderEnum)Enum.Parse(typeof(GenderEnum), model.Gender);
            dbContact.Link = model.ContactLink;
            dbContact.IsNameChecked = true;
            dbContact.ReadyToBuyScore = model.ReadyToBuyScore;
            dbContact.ReadyToSell = contactBusinessLogic.GetAllSellStatuses().First(x => x.Id == model.ReadyToSellId);
            //dbContact.Telephones = contact.Telephones.Split(';').ToList();
            dbContact.Status = contactBusinessLogic.GetAllStatuses().First(x => x.Id == model.StatusId);
            dbContact.Type = contactBusinessLogic.GetAllTypes().First(x => x.Id == model.ContactTypeId);
            dbContact.Name = model.Name;
            //dbContact.Id = model.Id;
            return dbContact;
        }
示例#2
0
        public string DoWork(CounterData data)
        {
            IncomingWebRequestContext context = WebOperationContext.Current?.IncomingRequest;
            data.Agent = context?
                .UserAgent;
            var coockie = data.Cookie.Replace('\"', ' ').Trim();
            Contact contact = _activityBusinessLogic.GetAllEntities()
                    .FirstOrDefault(x => (x.Cookie == coockie && x.UserAgent == data.Agent) || x.Ip == data.Ip)?
                    .Author;
            if (contact == null)
            {
                contact = new Contact
                {
                    Ip = data.Ip,
                    Name = data.Ip
                };
                contact.CreateDate = DateTime.Now;
                _contactBusinessLogic.Add(contact);
            }
            string returns = Guid.NewGuid().ToString();


            Activity activity = new Activity();
            activity.Author = contact;
            activity.CreateDate = DateTime.Now;
            if (data.Cookie != null)
            {
                activity.Cookie = data.Cookie;
            }
            else
            {
                activity.Cookie = returns;
            }
            activity.UserAgent = data.Agent;
            activity.Type = _activityBusinessLogic.GetActivityType(int.Parse(ActivityEnum.Visit.ToString("D")));
            //activity.TypeCode = int.Parse(ActivityEnum.Visit.ToString("D"));
            foreach (var item in data.Tags.Split(',').ToList())
            {
                var tag = _activityBusinessLogic.GetTagByName(item);
                if (tag != null)
                {
                    if (activity.Tag == null)
                    {
                        activity.Tag = new List<Tag>();
                    }
                    activity.Tag.Add(tag);
                }
                else
                {
                    //TODO Выпилить и выдавать ошибку в лог на этом этапе
                    var tg = new Tag { Name = item };
                    //activityLogic.Add(tg);
                    activity.Tag.Add(tg);
                }
            }
            _activityBusinessLogic.InsertNew(activity);
            return activity.Cookie;
        }
示例#3
0
        private static Contact TryAddContact(string id, string name )
        {
            try
            {
                var contactBusinessLogic = new ContactBusinessLogic(new ContactRepository(_factory),
                    new DictionaryBusinessLogic<ContactType>(new DictionaryRepository<ContactType>(_factory)),
                    new DictionaryBusinessLogic<ContactStatus>(new DictionaryRepository<ContactStatus>(_factory)),
                    new DictionaryBusinessLogic<AgeDirection>(new DictionaryRepository<AgeDirection>(_factory)),
                    new DictionaryBusinessLogic<ReadyToSellState>(new DictionaryRepository<ReadyToSellState>(_factory)));


                var contact = new Contact()
                {
                    Ip = id,
                    Name = name,
                    Link = "https://www.facebook.com/app_scoped_user_id/" + id + "/",
                    Gender = GenderEnum.Unknown
                };

                var existContact = contactBusinessLogic.GetByIp(id);
                if (existContact == null)
                {
                    contactBusinessLogic.Add(contact);
                    return contact;
                }
                return existContact;
            }
            catch (Exception ex)
            {
                throw;
            }
        }
示例#4
0
 public ActionResult Add(ContactModel contact)
 {
     var dbContact = _contactBusinessLogic.GetById(contact.Id);
     if (dbContact == null)
     {
         dbContact = new Contact();
     }
     dbContact.Age = _contactBusinessLogic.GetAllAges().First(x => x.Id == contact.AgeDirectionId);
     dbContact.BirthDate = contact.BirthDate;
     dbContact.Comment = contact.Comment;
     dbContact.CreateDate = DateTime.Now;
     dbContact.Email = contact.Email;
     dbContact.Ip = contact.ContactIp;
     dbContact.Gender = (GenderEnum)Enum.Parse(typeof(GenderEnum), contact.Gender);
     dbContact.Link = contact.ContactLink;
     dbContact.IsNameChecked = true;
     dbContact.ReadyToBuyScore = contact.ReadyToBuyScore;
     dbContact.ReadyToSell = _contactBusinessLogic.GetAllSellStatuses().First(x => x.Id == contact.ReadyToSellId);
     //dbContact.Telephones = contact.Telephones.Split(';').ToList();
     dbContact.Status = _contactBusinessLogic.GetAllStatuses().First(x => x.Id == contact.StatusId);
     dbContact.Type = _contactBusinessLogic.GetAllTypes().First(x => x.Id == contact.ContactTypeId);
     dbContact.Name = contact.Name;
     _contactBusinessLogic.Add(dbContact);
     return RedirectToAction("List");
 }