Example #1
0
        /// <summary>
        /// Saves the ModelRiskAlertAttachment.
        /// </summary>
        /// <param name="modelRiskAlertAttachment"></param>
        /// <returns></returns>
        public static ModelRiskAlertAttachment Save(ModelRiskAlertAttachment modelRiskAlertAttachment)
        {
            using (IdeaContext context = ContextManager.GetNewDataContext())
            {
                context.ModelRiskAlertAttachments.AddOrUpdate(modelRiskAlertAttachment);
                context.SaveChanges();
                //Document attachmentDocument = new Document();

                // attachmentDocument.Content = Convert.ToBase64String(Encoding.ASCII.GetBytes(modelRiskAlertAttachment.Content));

                string path     = DirectoryAndFileHelper.ServerAppDataFolder + ConfigurationManager.AppSettings["RARDocumentsFolder"];
                string fileName = modelRiskAlertAttachment.IDModelRiskAlertAttachment + "-" + modelRiskAlertAttachment.AttachmentFile;
                if (!File.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                //attachmentDocument.Filename = Path.GetFileName(path + fileName);
                //attachmentDocument.DocumentType = ERMTDocumentType.Document;



                DocumentManager.Save(path + fileName, Convert.FromBase64String(modelRiskAlertAttachment.Content));

                return(modelRiskAlertAttachment);
            }
        }
Example #2
0
 /// <summary>
 /// Delete the ModelRiskAlertAttachment.
 /// </summary>
 /// <param name="modelRiskAlertAttachment"></param>
 public static void Delete(ModelRiskAlertAttachment modelRiskAlertAttachment)
 {
     using (IdeaContext context = ContextManager.GetNewDataContext())
     {
         ModelRiskAlertAttachment mraa =
             context.ModelRiskAlertAttachments.FirstOrDefault(
                 mraa2 => mraa2.IDModelRiskAlertAttachment == modelRiskAlertAttachment.IDModelRiskAlertAttachment);
         context.ModelRiskAlertAttachments.Remove(mraa);
         context.SaveChanges();
     }
 }
        private void addUpdater(ModelRiskAlertAttachment att)
        {
            Updater newUpdater = new Updater();

            // Set properties:
            newUpdater.HasChange = false;
            newUpdater.HasFile   = true;
            newUpdater.Id        = att.IDModelRiskAlertAttachment;
            newUpdater.FileName  = att.AttachmentFile;
            if (att.Content != null)
            {
                newUpdater.Content = Convert.FromBase64String(att.Content);
            }
            newUpdater.Margin = new Padding(5);
            newUpdater.Size   = new Size(217, 31);


            // Set events:
            newUpdater.Delete += new Updater.DUpdater(DeleteAttachment);

            // Save
            analysisPanel.Controls.Add(newUpdater);
        }
 public void DeleteAttachment(ModelRiskAlertAttachment modelRiskAlertAttachment)
 {
     ModelRiskAlertAttachmentManager.Delete(modelRiskAlertAttachment);
 }
 public void SaveAttachment(ModelRiskAlertAttachment modelRiskAlertAttachment)
 {
     ModelRiskAlertAttachmentManager.Save(modelRiskAlertAttachment);
 }
        private void btnSaveRiskAndAction_Click(object sender, EventArgs e)
        {
            if (isValid())
            {
                // Save data:
                Model model = ERMTSession.Instance.CurrentModel;
                _alert.IDModel         = model.IDModel;
                _alert.Code            = tbCode.Text;
                _alert.Title           = tbTitle.Text;
                _alert.DateFrom        = Convert.ToDateTime(dtpDateFrom.Value);
                _alert.DateTo          = Convert.ToDateTime(dtpDateTo.Value);
                _alert.RiskDescription = tbDescription.Text;
                _alert.Action          = tbAction.Text;
                _alert.Result          = tbResult.Text;
                _alert.Active          = rbStatusActive.Checked;

                List <ModelRiskAlertPhase> modelRiskAlertPhaseListToSave = new List <ModelRiskAlertPhase>();
                ModelRiskAlertPhase        modelRiskAlertPhase           = null;
                List <ModelRiskAlertPhase> modelRiskAlertPhaseList       = ModelRiskAlertHelper.GetPhases(_alert);
                foreach (var lbPhase in lbElectoralPhases.Items)
                {
                    bool found = false;
                    foreach (ModelRiskAlertPhase oPhase in modelRiskAlertPhaseList)
                    {
                        if (((ComboBoxItemFace)lbPhase).IFase.IDPhase == oPhase.IDPhase)
                        {
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        modelRiskAlertPhase         = new ModelRiskAlertPhase();
                        modelRiskAlertPhase.IDPhase = ((ComboBoxItemFace)lbPhase).IFase.IDPhase;
                        modelRiskAlertPhaseListToSave.Add(modelRiskAlertPhase);
                    }
                }

                List <ModelRiskAlertRegion> modelRiskAlertRegionList      = ModelRiskAlertHelper.GetModelRiskAlertRegions(_alert);
                List <ModelRiskAlertRegion> modelRiskAlertRegionsToDelete = GetModelRiskAlertRegionsToDelete(modelRiskAlertRegionList);
                List <int> regionIDsToAdd = GetRegionIDsToAdd(modelRiskAlertRegionList);

                // Add new attachments:
                foreach (Control control in analysisPanel.Controls)
                {
                    if (control is Updater)
                    {
                        if (((Updater)control).HasFile && ((Updater)control).Id == 0)
                        {
                            ModelRiskAlertAttachment att = new ModelRiskAlertAttachment();
                            att.IDModelRiskAlert = _alert.IDModelRiskAlert;
                            att.AttachmentFile   = ((Updater)control).FileName; // Nombre del archivo, sin el ID adelante.
                            att.Content          = Convert.ToBase64String(((Updater)control).Content);

                            ModelRiskAlertHelper.SaveAttachment(att);
                        }
                    }
                }

                // Save the Alert:
                _alert = ModelRiskAlertHelper.Save(_alert);
                if (modelRiskAlertPhaseListToSave.Count > 0)
                {
                    foreach (ModelRiskAlertPhase mrap in modelRiskAlertPhaseListToSave)
                    {
                        mrap.IDModelRiskAlert = _alert.IDModelRiskAlert;
                        ModelRiskAlertHelper.SavePhase(mrap);
                    }
                }
                if (regionIDsToAdd.Count > 0)
                {
                    foreach (int regionID in regionIDsToAdd)
                    {
                        ModelRiskAlertRegion mrar = new ModelRiskAlertRegion();
                        mrar.IDModelRiskAlert = _alert.IDModelRiskAlert;
                        mrar.IDRegion         = regionID;
                        ModelRiskAlertHelper.SaveRegion(mrar);
                    }
                }
                if (modelRiskAlertRegionsToDelete.Count > 0)
                {
                    foreach (ModelRiskAlertRegion mrar in modelRiskAlertRegionsToDelete)
                    {
                        ModelRiskAlertHelper.DeleteRegion(mrar);
                    }
                }


                this.Close();
                CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("RiskAlertSaved"));
            }
        }
 public static void DeleteAttachment(ModelRiskAlertAttachment modelRiskAlertAttachment)
 {
     GetService().DeleteAttachment(modelRiskAlertAttachment);
 }
 /// <summary>
 /// Saves the ModelRiskAlertAttachment (service).
 /// </summary>
 /// <param name="modelRiskAlertAttachment"></param>
 public static void SaveAttachment(ModelRiskAlertAttachment modelRiskAlertAttachment)
 {
     GetService().SaveAttachment(modelRiskAlertAttachment);
 }