public FileUploadResult ProcessUpload(HttpContext context)
        {
            var result = new FileUploadResult();

            try
            {
                SecurityContext.CheckPermissions(Constants.Action_AddRemoveUser);

                if (context.Request.Files.Count != 0)
                {
                    var logo = context.Request.Files[0];
                    var ext  = FileUtility.GetFileExtension(logo.FileName);

                    if (ext != ".csv")
                    {
                        result.Success = false;
                        result.Message = Resource.ErrorEmptyUploadFileSelected;
                        return(result);
                    }

                    IUserImporter importer = context.Request["obj"] == "txt"
                                                 ? new TextFileUserImporter(logo.InputStream)
                    {
                        DefaultHeader = "Email;FirstName;LastName",
                    }
                                                 : new OutlookCSVUserImporter(logo.InputStream);

                    var users = importer.GetDiscoveredUsers();

                    result.Success = true;
                    result.Message = JsonContacts(users);
                }
                else
                {
                    result.Success = false;
                    result.Message = Resource.ErrorEmptyUploadFileSelected;
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message.HtmlEncode();
            }

            return(result);
        }
Beispiel #2
0
        public FileUploadResult ProcessUpload(HttpContext context)
        {
            FileUploadResult result = new FileUploadResult();

            try
            {
                if (context.Request.Files.Count != 0)
                {
                    var logo = context.Request.Files[0];

                    if (!(logo.ContentType == "text/plain" || logo.ContentType == "application/octet-stream" || logo.ContentType == "text/comma-separated-values"))
                    {
                        result.Success = false;
                        result.Message = Resources.Resource.ErrorEmptyUploadFileSelected;
                        return(result);
                    }

                    IUserImporter importer = null;
                    importer = context.Request["obj"] == "txt" ? new TextFileUserImporter(logo.InputStream)
                    {
                        DefaultHeader = "Email;FirstName;LastName",
                    } : new OutlookCSVUserImporter(logo.InputStream);

                    var users = importer.GetDiscoveredUsers();

                    result.Success = true;
                    result.Message = JsonContacts(users);
                }
                else
                {
                    result.Success = false;
                    result.Message = Resources.Resource.ErrorEmptyUploadFileSelected;
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message.HtmlEncode();
            }

            return(result);
        }