示例#1
0
 public virtual async Task CreateContactInfo(CreateContactInfo input)
 {
     var ContactInfos = input.MapTo <ContactInfo>();
     await _NewContactInfoRepository.InsertAsync(ContactInfos);
 }
示例#2
0
        public virtual async Task UpdateContactInfo(CreateContactInfo input)
        {
            var ContactInfo1 = input.MapTo <NewContactInfo>();
            var ContactInfo  = await _NewContactInfoRepository.GetAsync(input.Id);

            ObjectMapper.Map(input, ContactInfo);

            if (input.NewInfoTypeId == 4)
            {
                var currentDomain = Regex.Match(input.InfoData, "@.*").Value;
                if (input.NewCompanyId > 0)
                {
                    var query = _NewContactInfoRepository.GetAll().Where(p => (p.NewInfoTypeId == 4 && p.NewCompanyId > 0 && p.NewCompanyId != ContactInfo.NewCompanyId) && p.Id != input.Id && Regex.Match(p.InfoData, "@.*").Value == currentDomain).ToList();
                    if (query.Count() > 0)
                    {
                        var Ignoredomain = _EmaildomainRepository.GetAll().Where(p => p.EmaildomainName == currentDomain.Substring(1, currentDomain.Length - 1)).FirstOrDefault();
                        if (Ignoredomain != null)
                        {
                            var query1 = _NewContactInfoRepository.GetAll().Where(p => (p.NewInfoTypeId == 4 && p.InfoData == input.InfoData) && p.Id != input.Id).FirstOrDefault();
                            if (query1 == null)
                            {
                                try
                                {
                                    await _NewContactInfoRepository.UpdateAsync(ContactInfo);
                                }catch (Exception ex)
                                {
                                }
                            }
                            else
                            {
                                // throw new UserFriendlyException("Ooops!", "Duplicate Data Occured in data info '" + input.InfoData + "'...");
                            }
                        }
                        else
                        {
                            //throw new UserFriendlyException("Ooops!", "Duplicate Data Occured in Email Domain '" + currentDomain + "'...");
                        }
                    }
                    else
                    {
                        var dup = _NewContactInfoRepository.GetAll().Where(p => (p.NewInfoTypeId == 4 && p.NewCompanyId == ContactInfo.NewCompanyId && p.InfoData == input.InfoData) && p.Id != input.Id).FirstOrDefault();
                        if (dup == null)
                        {
                            try
                            {
                                await _NewContactInfoRepository.UpdateAsync(ContactInfo);
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                        else
                        {
                        }
                        //throw new UserFriendlyException("Ooops!", "Duplicate Data Occured in data info '" + input.InfoData + "'...");
                    }
                }
                if (input.NewContacId > 0)
                {
                    var cmp       = _NewContactRepository.GetAll().Where(p => p.Id == input.NewContacId).FirstOrDefault();
                    var companyId = cmp.NewCompanyId;
                    var query     = (from ci in _NewContactInfoRepository.GetAll()
                                     join c in _NewContactRepository.GetAll() on ci.NewContacId equals c.Id
                                     where ci.NewInfoTypeId == 4 && ci.NewContacId > 0 && c.NewCompanyId != companyId && Regex.Match(ci.InfoData, "@.*").Value == currentDomain
                                     select ci).ToList();
                    if (query.Count() > 0)
                    {
                        var Ignoredomain = _EmaildomainRepository.GetAll().Where(p => p.EmaildomainName == currentDomain.Substring(1, currentDomain.Length - 1)).FirstOrDefault();
                        if (Ignoredomain != null)
                        {
                            var query1 = _NewContactInfoRepository.GetAll().Where(p => p.NewInfoTypeId == 4 && p.InfoData == input.InfoData && p.Id != input.Id).FirstOrDefault();
                            if (query1 == null)
                            {
                                try
                                {
                                    await _NewContactInfoRepository.UpdateAsync(ContactInfo);
                                }
                                catch (Exception ex)
                                {
                                }
                            }
                            else
                            {
                                //throw new UserFriendlyException("Ooops!", "Duplicate Data Occured in data info '" + input.InfoData + "'...");
                            }
                        }
                        else
                        {
                            //throw new UserFriendlyException("Ooops!", "Duplicate Data Occured in Email Domain '" + currentDomain + "'...");
                        }
                    }
                    else
                    {
                        var dup = _NewContactInfoRepository.GetAll().Where(p => p.NewInfoTypeId == 4 && p.InfoData == input.InfoData).FirstOrDefault();
                        if (dup == null)
                        {
                            try
                            {
                                await _NewContactInfoRepository.UpdateAsync(ContactInfo);
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                        else
                        {
                        }
                        // throw new UserFriendlyException("Ooops!", "Duplicate Data Occured in data info '" + input.InfoData + "'...");
                    }
                }
            }
            else if (input.NewInfoTypeId == 7)
            {
                var val = _NewContactInfoRepository.GetAll().Where(p => p.InfoData == input.InfoData && p.NewInfoTypeId == input.NewInfoTypeId && p.Id != input.Id).FirstOrDefault();
                if (val == null)
                {
                    try
                    {
                        await _NewContactInfoRepository.UpdateAsync(ContactInfo);
                    }
                    catch (Exception ex)
                    {
                    }
                }
                else
                {
                    //throw new UserFriendlyException("Ooops!", "Duplicate Data Occured in data info '" + input.InfoData + "'...");
                }
            }
            else
            {
                try
                {
                    await _NewContactInfoRepository.UpdateAsync(ContactInfo);
                }
                catch (Exception ex)
                {
                }
            }
        }