public CompanyWrapper CreateCompany( string companyName, string about, IEnumerable<int> personList, ShareType shareType, IEnumerable<Guid> managerList, IEnumerable<ItemKeyValuePair<int, string>> customFieldList, IEnumerable<HttpPostedFileBase> photo) { var companyInst = new Company { CompanyName = companyName, About = about, ShareType = shareType }; companyInst.ID = DaoFactory.GetContactDao().SaveContact(companyInst); companyInst.CreateBy = Core.SecurityContext.CurrentAccount.ID; companyInst.CreateOn = DateTime.UtcNow; if (personList != null) { foreach (var personID in personList) { var person = DaoFactory.GetContactDao().GetByID(personID); if (person == null || !CRMSecurity.CanAccessTo(person)) continue; AddPeopleToCompany(companyInst.ID, personID); } } var managerListLocal = managerList != null ? managerList.ToList() : new List<Guid>(); if (managerListLocal.Any()) { CRMSecurity.SetAccessTo(companyInst, managerListLocal); } if (customFieldList != null) { var existingCustomFieldList = DaoFactory.GetCustomFieldDao().GetFieldsDescription(EntityType.Company).Select(fd => fd.ID).ToList(); foreach (var field in customFieldList) { if (string.IsNullOrEmpty(field.Value) || !existingCustomFieldList.Contains(field.Key)) continue; DaoFactory.GetCustomFieldDao().SetFieldValue(EntityType.Company, companyInst.ID, field.Key, field.Value); } } var wrapper = (CompanyWrapper)ToContactWrapper(companyInst); var photoList = photo != null ? photo.ToList() : new List<HttpPostedFileBase>(); if (photoList.Any()) { wrapper.SmallFotoUrl = ChangeContactPhoto(companyInst.ID, photoList); } MessageService.Send(Request, MessageAction.CompanyCreated, companyInst.GetTitle()); return wrapper; }
public String AddNewContact(bool isCompany, string companyName, string firstName, string lastName) { if (isCompany) { var company = new Company { CompanyName = companyName.Trim() }; company.ID = Global.DaoFactory.GetContactDao().SaveContact(company); CRMSecurity.MakePublic(company); return JsonConvert.SerializeObject(new { id = company.ID, title = company.GetTitle().HtmlEncode(), img = ContactPhotoManager.GetSmallSizePhoto(company.ID, true) }); } else { var contact = new Person { FirstName = firstName.Trim(), LastName = lastName.Trim() }; contact.ID = Global.DaoFactory.GetContactDao().SaveContact(contact); CRMSecurity.MakePublic(contact); return JsonConvert.SerializeObject(new { id = contact.ID, title = contact.GetTitle().HtmlEncode(), img = ContactPhotoManager.GetSmallSizePhoto(contact.ID, false) }); } }
public CompanyWrapper UpdateCompany( int companyid, string companyName, string about, ShareType shareType, IEnumerable<Guid> managerList, IEnumerable<ItemKeyValuePair<int, string>> customFieldList) { var companyInst = new Company { ID = companyid, CompanyName = companyName, About = about, ShareType = shareType }; DaoFactory.GetContactDao().UpdateContact(companyInst); companyInst = (Company)DaoFactory.GetContactDao().GetByID(companyInst.ID); var managerListLocal = managerList != null ? managerList.ToList(): new List<Guid>(); if (managerListLocal.Any()) { CRMSecurity.SetAccessTo(companyInst, managerListLocal); } if (customFieldList != null) { var existingCustomFieldList = DaoFactory.GetCustomFieldDao().GetFieldsDescription(EntityType.Company).Select(fd => fd.ID).ToList(); foreach (var field in customFieldList) { if (string.IsNullOrEmpty(field.Value) || !existingCustomFieldList.Contains(field.Key)) continue; DaoFactory.GetCustomFieldDao().SetFieldValue(EntityType.Company, companyInst.ID, field.Key, field.Value); } } MessageService.Send(Request, MessageAction.CompanyUpdated, companyInst.GetTitle()); return (CompanyWrapper)ToContactWrapper(companyInst); }
public static CompanyWrapper ToCompanyWrapperQuick(Company company) { var result = new CompanyWrapper(company.ID); result.DisplayName = company.GetTitle(); result.IsPrivate = CRMSecurity.IsPrivate(company); result.IsShared = company.ShareType == ShareType.ReadWrite || company.ShareType == ShareType.Read; result.ShareType = company.ShareType; if (result.IsPrivate) { result.AccessList = CRMSecurity.GetAccessSubjectTo(company) .Select(item => EmployeeWraper.Get(item.Key)); } result.Currency = !String.IsNullOrEmpty(company.Currency) ? new CurrencyInfoWrapper(CurrencyProvider.Get(company.Currency)) : null; result.SmallFotoUrl = String.Format("{0}HttpHandlers/filehandler.ashx?action=contactphotoulr&cid={1}&isc={2}&ps=1", PathProvider.BaseAbsolutePath, company.ID, true).ToLower(); result.MediumFotoUrl = String.Format("{0}HttpHandlers/filehandler.ashx?action=contactphotoulr&cid={1}&isc={2}&ps=2", PathProvider.BaseAbsolutePath, company.ID, true).ToLower(); result.IsCompany = true; result.CanEdit = CRMSecurity.CanEdit(company); //result.CanDelete = CRMSecurity.CanDelete(contact); result.CompanyName = company.CompanyName; result.CreateBy = EmployeeWraper.Get(company.CreateBy); result.Created = (ApiDateTime)company.CreateOn; result.About = company.About; result.Industry = company.Industry; return result; }