示例#1
0
        public ActivitiesFileViewModel UploadFileAttachment()
        {
            //inputModel needs creating here rather than passed in as a paramter to prevent HTTP 415 errors caused by multipart/form-data requests
            ActivitiesFileInputModel inputModel = new ActivitiesFileInputModel();
            ActivitiesFileViewModel  viewModel  = new ActivitiesFileViewModel();
            var file = HttpContext.Current.Request.Files.Count > 0 ? HttpContext.Current.Request.Files[0] : null;

            if (file != null && file.ContentLength > 0)
            {
                inputModel.Source          = "W";
                inputModel.qqfile          = HttpContext.Current.Request["qqfile"];
                inputModel.qqfilename      = HttpContext.Current.Request["qqfilename"];
                inputModel.qqtotalfilesize = HttpContext.Current.Request["qqtotalfilesize"];
                inputModel.qquuid          = HttpContext.Current.Request["qquuid"];

                inputModel.ActivityFileName           = file.FileName;
                inputModel.SessionID                  = HttpContext.Current.Request["SessionID"];
                inputModel.TemplateID                 = Convert.ToInt16(HttpContext.Current.Request["TemplateID"]);
                inputModel.CustomerActivitiesHeaderID = HttpContext.Current.Request["CustomerActivitiesHeaderID"];
                inputModel.ActivityFileDescription    = HttpContext.Current.Request["ActivityFileDescription"];
                inputModel.ActivityFileItemIndex      = HttpContext.Current.Request["ActivityFileItemIndex"];
                viewModel = new ActivitiesModelBuilder().CreateActivityFileAttachment(inputModel, file);
                if (!viewModel.Error.HasError)
                {
                    viewModel.HTMLContent = ViewRenderer.RenderView("~/Views/PartialViews/_ActivitiesFileAttachment.cshtml", viewModel, null);
                }
            }
            else
            {
                viewModel.success = false;
            }
            return(viewModel);
        }
示例#2
0
        /// <summary>
        /// Delete an existing activity file for an existing activity record, if that succeeds then delete the local file
        /// </summary>
        /// <param name="inputModel">The input model for editing an activity</param>
        /// <returns>Error model of results</returns>
        public ErrorModel DeleteActivityFileAttachment(ActivitiesFileInputModel inputModel)
        {
            ErrorModel       errModel     = new ErrorModel();
            TalentActivities talActivites = new TalentActivities();

            Mapper.CreateMap <ActivitiesFileInputModel, DEActivities>();
            ErrorObj  err = new ErrorObj();
            DataTable dtActivityTemplate = new DataTable();
            string    fileSavePath       = string.Empty;

            talActivites.De       = Mapper.Map <DEActivities>(inputModel);
            talActivites.Settings = Environment.Settings.DESettings;
            talActivites.Settings.AgentEntity.AgentUsername = Environment.Agent.GetAgentUserNameBySessionId(inputModel.SessionID);
            err      = talActivites.DeleteActivityFileAttachment();
            errModel = Data.PopulateErrorObject(err, talActivites.ResultDataSet, talActivites.Settings, 2);
            if (!errModel.HasError)
            {
                dtActivityTemplate = TDataObjects.ActivitiesSettings.GetActivityTemplatesTypeByBUTemplateID(Environment.Settings.BusinessUnit, inputModel.TemplateID);
                if (dtActivityTemplate.Rows.Count > 0)
                {
                    fileSavePath = dtActivityTemplate.Rows[0]["LOCAL_ROOT_DIRECTORY"].ToString();
                    if (fileSavePath.Length > 0)
                    {
                        if (!fileSavePath.EndsWith(@"\"))
                        {
                            fileSavePath = fileSavePath + @"\";
                        }
                        if (File.Exists(fileSavePath + inputModel.ActivityFileName))
                        {
                            try
                            {
                                File.Delete(fileSavePath + inputModel.ActivityFileAttachmentID + '_' + inputModel.ActivityFileName);
                            }
                            catch (Exception ex)
                            {
                                errModel.HasError     = true;
                                errModel.ReturnCode   = ex.Source;
                                errModel.ErrorMessage = ex.Message;
                            }
                        }
                    }
                }
            }
            return(errModel);
        }
示例#3
0
        /// <summary>
        /// Create the file attachment record and save the file locally. Handle any errors and set the error on the fineuploader error JSON response
        /// </summary>
        /// <param name="inputModel">The fine uploader based input model</param>
        /// <param name="postedFile">The file being posted</param>
        /// <returns>The view model with error and fine uploader JSON response</returns>
        public ActivitiesFileViewModel CreateActivityFileAttachment(ActivitiesFileInputModel inputModel, HttpPostedFile postedFile)
        {
            ActivitiesFileViewModel viewModel = new ActivitiesFileViewModel(true, "EditProfileActivity.ascx");
            ErrorModel       errModel         = new ErrorModel();
            TalentActivities talActivites     = new TalentActivities();

            Mapper.CreateMap <ActivitiesFileInputModel, DEActivities>();
            ErrorObj  err = new ErrorObj();
            DataTable dtActivityTemplate        = new DataTable();
            DataTable dtActivityFileAttachments = new DataTable();
            string    fileName     = string.Empty;
            string    fileSavePath = string.Empty;
            string    remotePath   = string.Empty;

            talActivites.De       = Mapper.Map <DEActivities>(inputModel);
            talActivites.Settings = Environment.Settings.DESettings;
            talActivites.Settings.AgentEntity.AgentUsername = Environment.Agent.GetAgentUserNameBySessionId(inputModel.SessionID);
            err      = talActivites.CreateActivityFileAttachment();
            errModel = Data.PopulateErrorObject(err, talActivites.ResultDataSet, talActivites.Settings, 2);

            if (!errModel.HasError)
            {
                dtActivityTemplate = TDataObjects.ActivitiesSettings.GetActivityTemplatesTypeByBUTemplateID(Environment.Settings.BusinessUnit, inputModel.TemplateID);
                if (dtActivityTemplate.Rows.Count > 0)
                {
                    fileSavePath = dtActivityTemplate.Rows[0]["LOCAL_ROOT_DIRECTORY"].ToString();
                    remotePath   = dtActivityTemplate.Rows[0]["REMOTE_ROOT_DIRECTORY"].ToString();
                    /** Activities is a BUI function and needs the BU on the output URL*/
                    remotePath = @"/" + Environment.Settings.BusinessUnit.Trim() + remotePath;
                    if (fileSavePath.Length > 0 && remotePath.Length > 0)
                    {
                        if (!fileSavePath.EndsWith(@"\"))
                        {
                            fileSavePath = fileSavePath + @"\";
                        }
                        if (!remotePath.EndsWith(@"\"))
                        {
                            remotePath = remotePath + @"/";
                        }
                        fileName = talActivites.De.ActivityFileAttachmentID.ToString() + "_" + inputModel.ActivityFileName;
                        if (!File.Exists(fileSavePath + fileName))
                        {
                            try
                            {
                                postedFile.SaveAs(fileSavePath + fileName);
                            }
                            catch (Exception ex)
                            {
                                errModel.HasError     = true;
                                errModel.ReturnCode   = ex.Source;
                                errModel.ErrorMessage = viewModel.GetControlText("ProblemUploadingErrorText");
                            }
                        }
                        else
                        {
                            errModel.HasError = true;
                            viewModel.GetControlText("FileAlreadyExistsErrorText");
                        }
                    }
                    else
                    {
                        errModel.HasError = true;
                        viewModel.GetControlText("ProblemWithSetupErrorText");
                    }
                }
                else
                {
                    errModel.HasError = true;
                    viewModel.GetControlText("ProblemWithSetupErrorText");
                }
            }

            viewModel.Error = errModel;
            if (errModel.HasError)
            {
                viewModel.error   = errModel.ErrorMessage;
                viewModel.success = false;
            }
            else
            {
                dtActivityFileAttachments = talActivites.ResultDataSet.Tables["CustomerActivitiesFileAttachments"];
                foreach (DataRow row in dtActivityFileAttachments.Rows)
                {
                    if (row["AttachmentID"].ToString() == talActivites.De.ActivityFileAttachmentID.ToString())
                    {
                        Agent       agentDefinition      = new Agent();
                        DateTime    dateAdded            = new DateTime();
                        TimeSpan    timeAdded            = new TimeSpan();
                        string      unformattedTimeAdded = string.Empty;
                        CultureInfo culture = new CultureInfo(Environment.Settings.DefaultValues.Culture);

                        dateAdded                             = Utilities.ISeries8CharacterDate(row["DateAdded"].ToString());
                        unformattedTimeAdded                  = row["TimeAdded"].ToString().PadLeft(6, '0');
                        timeAdded                             = TimeSpan.ParseExact(unformattedTimeAdded, "hhmmss", culture);
                        viewModel.ActivityFileDateAdded       = dateAdded.ToString(Environment.Settings.DefaultValues.GlobalDateFormat);
                        viewModel.ActivityFileTimeAdded       = timeAdded.ToString();
                        viewModel.ActivityDescriptiveUserName = agentDefinition.GetAgentDescriptiveNameByAgentUserCode(row["AgentName"].ToString());
                        viewModel.ActivityFileItemIndex       = inputModel.ActivityFileItemIndex;
                        viewModel.ActivityFileAttachmentID    = talActivites.De.ActivityFileAttachmentID.ToString();
                        viewModel.ActivityFileDescription     = inputModel.ActivityFileDescription;
                        viewModel.ActivityFileHasDescription  = (inputModel.ActivityFileDescription.Trim().Length > 0);
                        viewModel.ActivityFileName            = inputModel.ActivityFileName;
                        viewModel.ActivityFileLink            = remotePath + fileName;
                        viewModel.TemplateID                  = inputModel.TemplateID.ToString();
                        viewModel.ActivityFileAttachmentBlurb = viewModel.GetControlText("FileAttachmentBlurbText");
                        viewModel.success                     = true;
                        break;
                    }
                }
            }
            return(viewModel);
        }
示例#4
0
 public ErrorModel DeleteFileAttachment([FromUri] ActivitiesFileInputModel inputModel)
 {
     inputModel.Source = "W";
     return(new ActivitiesModelBuilder().DeleteActivityFileAttachment(inputModel));
 }