Пример #1
0
        public FileUploadResult ProcessUpload(HttpContext context)
        {
            var fileUploadResult = new FileUploadResult();

            if (!ProgressFileUploader.HasFilesToUpload(context))
            {
                return(fileUploadResult);
            }

            var file = new ProgressFileUploader.FileToUpload(context);

            if (String.IsNullOrEmpty(file.FileName) || file.ContentLength == 0)
            {
                throw new InvalidOperationException("Invalid file.");
            }

            if (0 < SetupInfo.MaxImageUploadSize && SetupInfo.MaxImageUploadSize < file.ContentLength)
            {
                throw FileSizeComment.FileImageSizeException;
            }

            if (FileUtility.GetFileTypeByFileName(file.FileName) != FileType.Image)
            {
                throw new UnknownImageFormatException();
            }

            var photoUri = ContactPhotoManager.UploadPhoto(file.InputStream, Convert.ToInt32(context.Request["contactID"]));

            fileUploadResult.Success = true;
            fileUploadResult.Data    = photoUri;

            return(fileUploadResult);
        }
        public static void DataCasesActionView(BasePage page, ASC.CRM.Core.Entities.Cases targetCase)
        {
            var daoFactory      = page.DaoFactory;
            var customFieldList = targetCase != null
                ? daoFactory.CustomFieldDao.GetEnityFields(EntityType.Case, targetCase.ID, true)
                : daoFactory.CustomFieldDao.GetFieldsDescription(EntityType.Case);

            var tags = targetCase != null?daoFactory.TagDao.GetEntityTags(EntityType.Case, targetCase.ID) : new string[]
            {
            };
            var availableTags = daoFactory.TagDao.GetAllTags(EntityType.Case).Where(item => !tags.Contains(item));


            var presetContactsJson = "";
            var selectedContacts   = new List <Contact>();

            if (targetCase != null)
            {
                selectedContacts = daoFactory.ContactDao.GetContacts(daoFactory.CasesDao.GetMembers(targetCase.ID));
            }
            else
            {
                var URLContactID = UrlParameters.ContactID;
                if (URLContactID != 0)
                {
                    var target = daoFactory.ContactDao.GetByID(URLContactID);
                    if (target != null)
                    {
                        selectedContacts.Add(target);
                    }
                }
            }

            if (selectedContacts.Count > 0)
            {
                presetContactsJson = JsonConvert.SerializeObject(selectedContacts.ConvertAll(item => new
                {
                    id           = item.ID,
                    displayName  = item.GetTitle().HtmlEncode().ReplaceSingleQuote().Replace(@"\", @"\\"),
                    smallFotoUrl = ContactPhotoManager.GetSmallSizePhoto(item.ID, item is Company)
                }));
            }

            var script = String.Format(@"
                                        var casesActionTags = {0};
                                        var casesActionAvailableTags = {1};
                                        var casesActionSelectedContacts = '{2}'; ",
                                       JsonConvert.SerializeObject(tags.ToList().ConvertAll(t => t.HtmlEncode())),
                                       JsonConvert.SerializeObject(availableTags.ToList().ConvertAll(t => t.HtmlEncode())),
                                       presetContactsJson
                                       );

            page.RegisterInlineScript(script, onReady: false);
            page.JsonPublisher(customFieldList, "casesEditCustomFieldList");
        }
Пример #3
0
        public FileUploadResult ProcessUpload(HttpContext context)
        {
            var fileUploadResult = new FileUploadResult();

            if (!ProgressFileUploader.HasFilesToUpload(context))
            {
                return(fileUploadResult);
            }

            var file = new ProgressFileUploader.FileToUpload(context);

            if (String.IsNullOrEmpty(file.FileName) || file.ContentLength == 0)
            {
                throw new InvalidOperationException("Invalid file.");
            }

            if (0 < SetupInfo.MaxImageUploadSize && SetupInfo.MaxImageUploadSize < file.ContentLength)
            {
                fileUploadResult.Success = false;
                fileUploadResult.Message = FileSizeComment.GetFileImageSizeNote(CRMCommonResource.ErrorMessage_UploadFileSize, false).HtmlEncode();
                return(fileUploadResult);
            }

            if (FileUtility.GetFileTypeByFileName(file.FileName) != FileType.Image)
            {
                fileUploadResult.Success = false;
                fileUploadResult.Message = CRMJSResource.ErrorMessage_NotImageSupportFormat.HtmlEncode();
                return(fileUploadResult);
            }


            var contactId  = Convert.ToInt32(context.Request["contactID"]);
            var uploadOnly = Convert.ToBoolean(context.Request["uploadOnly"]);
            var tmpDirName = Convert.ToString(context.Request["tmpDirName"]);
            var photoUri   = "";

            if (contactId != 0)
            {
                photoUri = ContactPhotoManager.UploadPhoto(file.InputStream, contactId, uploadOnly);
            }
            else
            {
                if (String.IsNullOrEmpty(tmpDirName))
                {
                    tmpDirName = Guid.NewGuid().ToString();
                }
                photoUri = ContactPhotoManager.UploadPhoto(file.InputStream, tmpDirName);
            }
            fileUploadResult.Success = true;
            fileUploadResult.Data    = photoUri;

            return(fileUploadResult);
        }
        public FileUploadResult ProcessUpload(HttpContext context)
        {
            if (!CRMSecurity.IsAdmin)
            {
                throw CRMSecurity.CreateSecurityException();
            }

            var fileUploadResult = new FileUploadResult();

            if (!FileToUpload.HasFilesToUpload(context))
            {
                return(fileUploadResult);
            }

            var file = new FileToUpload(context);

            if (String.IsNullOrEmpty(file.FileName) || file.ContentLength == 0)
            {
                throw new InvalidOperationException(CRMErrorsResource.InvalidFile);
            }

            if (0 < SetupInfo.MaxImageUploadSize && SetupInfo.MaxImageUploadSize < file.ContentLength)
            {
                fileUploadResult.Success = false;
                fileUploadResult.Message = FileSizeComment.GetFileImageSizeNote(CRMCommonResource.ErrorMessage_UploadFileSize, false).HtmlEncode();
                return(fileUploadResult);
            }

            if (FileUtility.GetFileTypeByFileName(file.FileName) != FileType.Image)
            {
                fileUploadResult.Success = false;
                fileUploadResult.Message = CRMJSResource.ErrorMessage_NotImageSupportFormat.HtmlEncode();
                return(fileUploadResult);
            }

            try
            {
                var imageData   = Global.ToByteArray(file.InputStream);
                var imageFormat = ContactPhotoManager.CheckImgFormat(imageData);
                var photoUri    = OrganisationLogoManager.UploadLogo(imageData, imageFormat);

                fileUploadResult.Success = true;
                fileUploadResult.Data    = photoUri;
                return(fileUploadResult);
            }
            catch (Exception exception)
            {
                fileUploadResult.Success = false;
                fileUploadResult.Message = exception.Message.HtmlEncode();
                return(fileUploadResult);
            }
        }
        public static void DataContactDetailsViewForTaskAction(BasePage page, Contact TargetContact)
        {
            var isPrivate = !CRMSecurity.CanAccessTo(TargetContact);
            var contactAccessList = new List<Guid>();
            if (isPrivate)
            {
                contactAccessList = CRMSecurity.GetAccessSubjectTo(TargetContact).Keys.ToList<Guid>();
            }

            page.RegisterInlineScript(String.Format(" var contactForInitTaskActionPanel = {0}; ",
                                                    JsonConvert.SerializeObject(new
                                                    {
                                                        id = TargetContact.ID,
                                                        displayName = TargetContact.GetTitle().HtmlEncode().ReplaceSingleQuote(),
                                                        smallFotoUrl = ContactPhotoManager.GetSmallSizePhoto(TargetContact.ID, TargetContact is Company),
                                                        isPrivate = isPrivate,
                                                        accessList = contactAccessList.ConvertAll(n => new { id = n })
                                                    })), onReady: false);
        }
Пример #6
0
        public FileUploadResult ProcessUpload(HttpContext context)
        {
            if (!WebItemSecurity.IsAvailableForUser(ProductEntryPoint.ID.ToString(), SecurityContext.CurrentAccount.ID))
            {
                throw CRMSecurity.CreateSecurityException();
            }

            var     contactId = Convert.ToInt32(context.Request["contactID"]);
            Contact contact   = null;

            if (contactId != 0)
            {
                contact = Global.DaoFactory.GetContactDao().GetByID(contactId);
                if (!CRMSecurity.CanAccessTo(contact))
                {
                    throw CRMSecurity.CreateSecurityException();
                }
            }

            var fileUploadResult = new FileUploadResult();

            if (!FileToUpload.HasFilesToUpload(context))
            {
                return(fileUploadResult);
            }

            var file = new FileToUpload(context);

            if (String.IsNullOrEmpty(file.FileName) || file.ContentLength == 0)
            {
                throw new InvalidOperationException(CRMErrorsResource.InvalidFile);
            }

            if (0 < SetupInfo.MaxImageUploadSize && SetupInfo.MaxImageUploadSize < file.ContentLength)
            {
                fileUploadResult.Success = false;
                fileUploadResult.Message = FileSizeComment.GetFileImageSizeNote(CRMCommonResource.ErrorMessage_UploadFileSize, false).HtmlEncode();
                return(fileUploadResult);
            }

            if (FileUtility.GetFileTypeByFileName(file.FileName) != FileType.Image)
            {
                fileUploadResult.Success = false;
                fileUploadResult.Message = CRMJSResource.ErrorMessage_NotImageSupportFormat.HtmlEncode();
                return(fileUploadResult);
            }

            var uploadOnly = Convert.ToBoolean(context.Request["uploadOnly"]);
            var tmpDirName = Convert.ToString(context.Request["tmpDirName"]);

            try
            {
                string photoUri;
                if (contactId != 0)
                {
                    photoUri = ContactPhotoManager.UploadPhoto(file.InputStream, contactId, uploadOnly);
                }
                else
                {
                    if (String.IsNullOrEmpty(tmpDirName))
                    {
                        tmpDirName = Guid.NewGuid().ToString();
                    }
                    photoUri = ContactPhotoManager.UploadPhoto(file.InputStream, tmpDirName);
                }

                fileUploadResult.Success = true;
                fileUploadResult.Data    = photoUri;
            }
            catch (Exception e)
            {
                fileUploadResult.Success = false;
                fileUploadResult.Message = e.Message.HtmlEncode();
                return(fileUploadResult);
            }

            if (contact != null)
            {
                var messageAction = contact is Company ? MessageAction.CompanyUpdatedPhoto : MessageAction.PersonUpdatedPhoto;
                MessageService.Send(context.Request, messageAction, MessageTarget.Create(contact.ID), contact.GetTitle());
            }

            return(fileUploadResult);
        }
        public static void DataInvoicesActionView(BasePage page, Invoice targetInvoice)
        {
            var daoFactory       = page.DaoFactory;
            var invoiceItems     = daoFactory.InvoiceItemDao.GetAll();
            var invoiceItemsJson = JsonConvert.SerializeObject(invoiceItems.ConvertAll(item => new
            {
                id               = item.ID,
                title            = item.Title,
                stockKeepingUnit = item.StockKeepingUnit,
                description      = item.Description,
                price            = item.Price,
                quantity         = item.Quantity,
                stockQuantity    = item.StockQuantity,
                trackInventory   = item.TrackInventory,
                invoiceTax1ID    = item.InvoiceTax1ID,
                invoiceTax2ID    = item.InvoiceTax2ID
            }));

            var invoiceTaxes     = daoFactory.InvoiceTaxDao.GetAll();
            var invoiceTaxesJson = JsonConvert.SerializeObject(invoiceTaxes.ConvertAll(item => new
            {
                id          = item.ID,
                name        = item.Name,
                rate        = item.Rate,
                description = item.Description
            }));

            var invoiceSettings     = Global.TenantSettings.InvoiceSetting ?? InvoiceSetting.DefaultSettings;
            var invoiceSettingsJson = JsonConvert.SerializeObject(new
            {
                autogenerated = invoiceSettings.Autogenerated,
                prefix        = invoiceSettings.Prefix,
                number        = invoiceSettings.Number,
                terms         = invoiceSettings.Terms
            });

            var presetContactsJson = string.Empty;
            var presetContactID    = UrlParameters.ContactID;

            if (targetInvoice == null && presetContactID != 0)
            {
                var targetContact = daoFactory.ContactDao.GetByID(presetContactID);
                if (targetContact != null)
                {
                    presetContactsJson = JsonConvert.SerializeObject(new
                    {
                        id                   = targetContact.ID,
                        displayName          = targetContact.GetTitle().HtmlEncode().ReplaceSingleQuote(),
                        smallFotoUrl         = ContactPhotoManager.GetSmallSizePhoto(targetContact.ID, targetContact is Company),
                        currencyAbbreviation = targetContact.Currency
                    });
                }
            }

            var currencyRates     = daoFactory.CurrencyRateDao.GetAll();
            var currencyRatesJson = JsonConvert.SerializeObject(currencyRates.ConvertAll(item => new
            {
                id           = item.ID,
                fromCurrency = item.FromCurrency,
                toCurrency   = item.ToCurrency,
                rate         = item.Rate
            }));

            var          apiServer    = new Api.ApiServer();
            const string apiUrlFormat = "{0}crm/contact/{1}/data.json";

            var contactInfoData   = string.Empty;
            var consigneeInfoData = string.Empty;

            if (targetInvoice != null)
            {
                if (targetInvoice.ContactID > 0)
                {
                    contactInfoData = apiServer.GetApiResponse(String.Format(apiUrlFormat, SetupInfo.WebApiBaseUrl, targetInvoice.ContactID), "GET");
                }
                if (targetInvoice.ConsigneeID > 0)
                {
                    consigneeInfoData = apiServer.GetApiResponse(String.Format(apiUrlFormat, SetupInfo.WebApiBaseUrl, targetInvoice.ConsigneeID), "GET");
                }
            }
            else if (presetContactID != 0)
            {
                contactInfoData = apiServer.GetApiResponse(String.Format(apiUrlFormat, SetupInfo.WebApiBaseUrl, presetContactID), "GET");
            }

            var apiUrl = String.Format("{0}crm/invoice/{1}.json",
                                       SetupInfo.WebApiBaseUrl,
                                       targetInvoice != null ? targetInvoice.ID.ToString(CultureInfo.InvariantCulture) : "sample");
            var invoiceData = apiServer.GetApiResponse(apiUrl, "GET");

            var script = String.Format(@"
                                        var invoiceItems = '{0}';
                                        var invoiceTaxes = '{1}';
                                        var invoiceSettings = '{2}';
                                        var invoicePresetContact = '{3}';
                                        var currencyRates = '{4}';
                                        var invoiceJsonData = '{5}';",
                                       Global.EncodeTo64(invoiceItemsJson),
                                       Global.EncodeTo64(invoiceTaxesJson),
                                       Global.EncodeTo64(invoiceSettingsJson),
                                       Global.EncodeTo64(presetContactsJson),
                                       Global.EncodeTo64(currencyRatesJson),
                                       targetInvoice != null ? Global.EncodeTo64(targetInvoice.JsonData) : ""
                                       );

            page.RegisterInlineScript(script, onReady: false);
            page.JsonPublisher(contactInfoData, "invoiceContactInfo");
            page.JsonPublisher(consigneeInfoData, "invoiceConsigneeInfo");
            page.JsonPublisher(invoiceData, "invoice");
        }
        public static void DataDealActionView(BasePage page, Deal targetDeal)
        {
            var daoFactory      = page.DaoFactory;
            var customFieldList = targetDeal != null
                ? daoFactory.CustomFieldDao.GetEnityFields(EntityType.Opportunity, targetDeal.ID, true)
                : daoFactory.CustomFieldDao.GetFieldsDescription(EntityType.Opportunity);

            var dealExcludedIDs = new List <Int32>();
            var dealClientIDs   = new List <Int32>();
            var dealMembersIDs  = new List <Int32>();

            if (targetDeal != null)
            {
                dealExcludedIDs = daoFactory.DealDao.GetMembers(targetDeal.ID).ToList();
                dealMembersIDs  = new List <int>(dealExcludedIDs);
                if (targetDeal.ContactID != 0)
                {
                    dealMembersIDs.Remove(targetDeal.ContactID);
                    dealClientIDs.Add(targetDeal.ContactID);
                }
            }


            var presetClientContactsJson = "";
            var presetMemberContactsJson = "";
            var showMembersPanel         = false;
            var selectedContacts         = new List <Contact>();
            var hasTargetClient          = false;

            if (targetDeal != null && targetDeal.ContactID != 0)
            {
                var contact = daoFactory.ContactDao.GetByID(targetDeal.ContactID);
                if (contact != null)
                {
                    selectedContacts.Add(contact);
                }
            }
            else
            {
                var URLContactID = UrlParameters.ContactID;
                if (URLContactID != 0)
                {
                    var target = daoFactory.ContactDao.GetByID(URLContactID);
                    if (target != null)
                    {
                        selectedContacts.Add(target);
                        hasTargetClient = true;
                    }
                }
            }
            if (selectedContacts.Count > 0)
            {
                presetClientContactsJson = JsonConvert.SerializeObject(selectedContacts.ConvertAll(item => new
                {
                    id           = item.ID,
                    displayName  = item.GetTitle().HtmlEncode().ReplaceSingleQuote().Replace(@"\", @"\\"),
                    smallFotoUrl = ContactPhotoManager.GetSmallSizePhoto(item.ID, item is Company)
                }));
            }


            selectedContacts = new List <Contact>();
            selectedContacts.AddRange(daoFactory.ContactDao.GetContacts(dealMembersIDs.ToArray()));
            if (selectedContacts.Count > 0)
            {
                showMembersPanel         = true;
                presetMemberContactsJson = JsonConvert.SerializeObject(selectedContacts.ConvertAll(item => new
                {
                    id           = item.ID,
                    displayName  = item.GetTitle().HtmlEncode().ReplaceSingleQuote().Replace(@"\", @"\\"),
                    smallFotoUrl = ContactPhotoManager.GetSmallSizePhoto(item.ID, item is Company)
                }));
            }

            var ResponsibleSelectedUserId = targetDeal == null ?
                                            SecurityContext.CurrentAccount.ID :
                                            (targetDeal.ResponsibleID != Guid.Empty ? targetDeal.ResponsibleID : Guid.Empty);

            var script = String.Format(@"
                                            var presetClientContactsJson = '{0}';
                                            var presetMemberContactsJson = '{1}';
                                            var hasDealTargetClient = {2};
                                            var showMembersPanel = {3};
                                            var dealClientIDs = {4};
                                            var dealMembersIDs = {5};
                                            var responsibleId = '{6}'; ",
                                       presetClientContactsJson,
                                       presetMemberContactsJson,
                                       hasTargetClient.ToString().ToLower(),
                                       showMembersPanel.ToString().ToLower(),
                                       JsonConvert.SerializeObject(dealClientIDs),
                                       JsonConvert.SerializeObject(dealMembersIDs),
                                       ResponsibleSelectedUserId
                                       );

            page.RegisterInlineScript(script, onReady: false);
            page.JsonPublisher(customFieldList, "customFieldList");
            page.JsonPublisher(daoFactory.DealMilestoneDao.GetAll(), "dealMilestones");

            if (targetDeal != null)
            {
                page.JsonPublisher(targetDeal, "targetDeal");
            }
        }
        public static void DataContactActionView(BasePage page, Contact targetContact, List <CustomField> data, List <ContactInfo> networks)
        {
            var daoFactory = page.DaoFactory;

            var tags = targetContact != null?daoFactory.TagDao.GetEntityTags(EntityType.Contact, targetContact.ID) : new string[]
            {
            };
            var availableTags = daoFactory.TagDao.GetAllTags(EntityType.Contact).Where(item => !tags.Contains(item));

            String json;

            using (var stream = new MemoryStream())
            {
                var serializer = new DataContractJsonSerializer(data.GetType());
                serializer.WriteObject(stream, data);
                json = Encoding.UTF8.GetString(stream.ToArray());
            }

            var listItems = daoFactory.ListItemDao.GetItems(ListType.ContactType);

            var presetCompanyForPersonJson = "";

            if (targetContact != null && targetContact is Person && ((Person)targetContact).CompanyID > 0)
            {
                var company = daoFactory.ContactDao.GetByID(((Person)targetContact).CompanyID);
                if (company == null)
                {
                    LogManager.GetLogger("ASC.CRM").ErrorFormat("Can't find parent company (CompanyID = {0}) for person with ID = {1}", ((Person)targetContact).CompanyID, targetContact.ID);
                }
                else
                {
                    presetCompanyForPersonJson = JsonConvert.SerializeObject(new
                    {
                        id           = company.ID,
                        displayName  = company.GetTitle().HtmlEncode().ReplaceSingleQuote().Replace(@"\", @"\\"),
                        smallFotoUrl = ContactPhotoManager.GetSmallSizePhoto(company.ID, true)
                    });
                }
            }

            var presetPersonsForCompanyJson = "";

            if (targetContact != null && targetContact is Company)
            {
                var people = daoFactory.ContactDao.GetMembers(targetContact.ID);
                if (people.Count != 0)
                {
                    presetPersonsForCompanyJson = JsonConvert.SerializeObject(people.ConvertAll(item => new
                    {
                        id           = item.ID,
                        displayName  = item.GetTitle().HtmlEncode().ReplaceSingleQuote().Replace(@"\", @"\\"),
                        smallFotoUrl = ContactPhotoManager.GetSmallSizePhoto(item.ID, false)
                    }));
                }
            }

            var script = String.Format(@"
                                var customFieldList = {0};
                                var contactNetworks = {1};
                                var contactActionTags = {2};
                                var contactActionAvailableTags = {3};
                                var contactAvailableTypes = {4};
                                var presetCompanyForPersonJson = '{5}';
                                var presetPersonsForCompanyJson = '{6}';
                                var twitterSearchEnabled = {7};
                                var contactActionCurrencies = {8};",
                                       json,
                                       JsonConvert.SerializeObject(networks),
                                       JsonConvert.SerializeObject(tags.ToList().ConvertAll(t => t.HtmlEncode())),
                                       JsonConvert.SerializeObject(availableTags.ToList().ConvertAll(t => t.HtmlEncode())),
                                       JsonConvert.SerializeObject(
                                           listItems.ConvertAll(n => new
            {
                id    = n.ID,
                title = n.Title.HtmlEncode()
            })),
                                       presetCompanyForPersonJson,
                                       presetPersonsForCompanyJson,
                                       IsTwitterSearchEnabled.ToString().ToLower(),
                                       JsonConvert.SerializeObject(CurrencyProvider.GetAll())
                                       );

            page.RegisterInlineScript(script, onReady: false);
        }