예제 #1
0
        public async Task <IActionResult> Edit(int id, TipDocument tipDocument)
        {
            if (id != tipDocument.TipDocumentId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.TipDocument.Update(tipDocument);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TipDocumentExists(tipDocument.TipDocumentId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                TempData["Message"] = "Tip document actualizat cu succes!";
                TempData["Success"] = "true";
                return(RedirectToAction(nameof(Index)));
            }
            return(View(tipDocument));
        }
예제 #2
0
        // GET: TipDocuments/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TipDocument tipDocument = _db.TipDocuments.Find(id);

            if (tipDocument == null)
            {
                return(HttpNotFound());
            }

            List <SelectListItem> categoryList = new List <SelectListItem>();

            foreach (TipsCategory tipCategory in _db.TipsCategories)
            {
                if (tipDocument.Category.Id == tipCategory.Id)
                {
                    categoryList.Add(new SelectListItem {
                        Text = tipCategory.Name, Value = tipCategory.Id.ToString(), Selected = true
                    });
                }
                else
                {
                    categoryList.Add(new SelectListItem {
                        Text = tipCategory.Name, Value = tipCategory.Id.ToString(), Selected = false
                    });
                }
            }

            tipDocument.Categories = categoryList;

            return(View(tipDocument));
        }
예제 #3
0
        public async Task <IActionResult> Create(TipDocument tipDocument)
        {
            if (ModelState.IsValid)
            {
                _context.TipDocument.Add(tipDocument);
                await _context.SaveChangesAsync();

                TempData["Message"] = "Tip document adaugat cu succes!";
                TempData["Success"] = "true";
                return(RedirectToAction(nameof(Index)));
            }
            return(View(tipDocument));
        }
예제 #4
0
        // GET: TipDocuments/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TipDocument tipDocument = _db.TipDocuments.Find(id);

            if (tipDocument == null)
            {
                return(HttpNotFound());
            }
            return(View(tipDocument));
        }
예제 #5
0
        public ActionResult Edit([Bind(Include = "Id,Name,Category,DocumentLink,User")] TipDocument viewModel)
        {
            if (ModelState.IsValid)
            {
                var tipDocument = _db.TipDocuments.Find(viewModel.Id);
                if (tipDocument != null)
                {
                    tipDocument.Name         = viewModel.Name;
                    tipDocument.DocumentLink = viewModel.DocumentLink;
                    tipDocument.User         = (from u in _db.Users where u.Id == viewModel.User.Id select u).Single();
                    tipDocument.Category     = (from c in _db.TipsCategories where c.Id == viewModel.Category.Id select c).Single();
                }

                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("Index"));
        }
예제 #6
0
        private static string SaSutility(TipDocument document)
        // SAS == Shared Access Signature ; return a url to access report for 10 minutes:
        {
            var sasConstraints = new SharedAccessBlobPolicy
            {
                SharedAccessStartTime  = DateTime.UtcNow.AddMinutes(-5),
                SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(10),
                Permissions            = SharedAccessBlobPermissions.Read
            };

            // Parse the connection string and return a reference to the storage account.
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(Properties.Settings.Default.StorageConnectionString);
            CloudBlobClient     blobClient     = storageAccount.CreateCloudBlobClient();
            // Retrieve a reference to a container.
            CloudBlobContainer container = blobClient.GetContainerReference("teachingtips");
            // Retrieve reference to a blob named "myblob".
            CloudBlockBlob blockBlob = container.GetBlockBlobReference(document.DocumentLink);

            var sasBlobToken = blockBlob.GetSharedAccessSignature(sasConstraints);

            return(blockBlob.Uri + sasBlobToken);
        }
예제 #7
0
        public ActionResult DeleteConfirmed(int id)
        {
            TipDocument tipDocument = _db.TipDocuments.Find(id);

            if (tipDocument != null)
            {
                _db.TipDocuments.Remove(tipDocument);
                _db.SaveChanges();

                CloudStorageAccount storageAccount =
                    CloudStorageAccount.Parse(Settings.Default.StorageConnectionString);
                CloudBlobClient    blobClient = storageAccount.CreateCloudBlobClient();
                CloudBlobContainer container  = blobClient.GetContainerReference("teachingtips");
                CloudBlockBlob     blob       = container.GetBlockBlobReference(tipDocument.DocumentLink);
                if (blob.Exists())
                {
                    blob.Delete();
                }
            }

            return(RedirectToAction("Index"));
        }
예제 #8
0
파일: Program.cs 프로젝트: andpsy/socisaV2
        public static void CallService(bool WithoutEmails, bool WithoutMarkings, bool WithPdfs, string DenumireSocietate)
        {
            response r = new response();

            try
            {
                int           uid     = 1;
                List <string> conStrs = new List <string>();
                conStrs.Add(CommonFunctions.StringCipher.Decrypt(ConfigurationManager.ConnectionStrings["MySqlConnectionString"].ToString(), CommonFunctions.StringCipher.RetrieveKey()));
                //conStrs.Add(StringCipher.Decrypt( ConfigurationManager.ConnectionStrings["MySqlConnectionString_test"].ToString(), RetrieveKey()));  // -- daca vrem insert si in baza de test !!! dubleaza documentele in "scan"

                /*
                 * BasicHttpBinding binding = new BasicHttpBinding();
                 * binding.MaxBufferPoolSize = binding.MaxBufferSize = Int32.MaxValue;
                 * binding.MaxReceivedMessageSize = long.MaxValue;
                 */
                SubrogationServiceClient s = new SubrogationServiceClient();

                /*
                 * (s.ChannelFactory.Endpoint.Binding as BasicHttpBinding).MaxBufferPoolSize = Int32.MaxValue;
                 * (s.ChannelFactory.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = Int32.MaxValue;
                 * (s.ChannelFactory.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = Int32.MaxValue;
                 */

                s.ClientCredentials.UserName.UserName = CommonFunctions.StringCipher.Decrypt(ConfigurationManager.AppSettings["AllianzWSUser"].ToString(), CommonFunctions.StringCipher.RetrieveKey());
                s.ClientCredentials.UserName.Password = CommonFunctions.StringCipher.Decrypt(ConfigurationManager.AppSettings["AllianzWSPassword"].ToString(), CommonFunctions.StringCipher.RetrieveKey());

                s.InnerChannel.OperationTimeout = new TimeSpan(0, 10, 0);

                SubrogationInfo[] sis = s.BrowseUnreadSubrogations(DateTime.MinValue, DateTime.MinValue);
                int counter           = 0;
                foreach (SubrogationInfo si in sis)
                {
                    //if (counter > 2) return;
                    foreach (string conStr in conStrs) // salvam in ambele baze !
                    {
                        try
                        {
                            response            validationResponse = new response();
                            SOCISA.Models.Dosar d = new SOCISA.Models.Dosar(uid, conStr);
                            try
                            {
                                SocietateAsigurare sCasco = new SocietateAsigurare(uid, conStr, DenumireSocietate, true);
                                d.ID_SOCIETATE_CASCO = sCasco.ID;
                            }
                            catch (Exception exp) { LogWriter.Log(exp); }
                            try
                            {
                                //SocietateAsigurare sRca = new SocietateAsigurare(uid, conStr, si.SubrogationInsurerName, false);
                                SocietateAsigurare sRca = null;
                                int?id_soc = GetSocietateMapping(SocietatiMappings, si.SubrogationInsurerId);
                                if (id_soc != null && id_soc != 0)
                                {
                                    sRca = new SocietateAsigurare(uid, conStr, Convert.ToInt32(id_soc));
                                }
                                if (sRca == null || sRca.ID == null)
                                {
                                    sRca          = new SocietateAsigurare(uid, conStr);
                                    sRca.DENUMIRE = sRca.DENUMIRE_SCURTA = si.SubrogationInsurerName;
                                    sRca.ADRESA   = si.SubrogationInsurerCountry;
                                    r             = sRca.Insert();

                                    /*
                                     * if(r.InsertedId != null && id_soc == null)
                                     * {
                                     *  DataRow newRow = SocietatiMappings.NewRow();
                                     *  newRow["ID_SCA"] = r.InsertedId;
                                     *  newRow["ID_SOCIETATE"] = id_soc;
                                     *  SocietatiMappings.Rows.Add(newRow);
                                     *  SocietatiMappings.AcceptChanges();
                                     *  SaveSocietatiMappings(DenumireSocietate);
                                     * }
                                     */
                                }
                                d.ID_SOCIETATE_RCA = sRca.ID;
                            }
                            catch (Exception exp) { LogWriter.Log(exp); }

                            try
                            {
                                if (!String.IsNullOrWhiteSpace(si.InsuredFullName))
                                {
                                    Asigurat aCasco = new Asigurat(uid, conStr, si.InsuredFullName);
                                    if (aCasco == null || aCasco.ID == null)
                                    {
                                        aCasco          = new Asigurat(uid, conStr);
                                        aCasco.DENUMIRE = si.InsuredFullName;
                                        r = aCasco.Insert();
                                    }
                                    d.ID_ASIGURAT_CASCO = aCasco.ID;
                                }
                            }
                            catch (Exception exp) { LogWriter.Log(exp); }

                            try
                            {
                                if (!String.IsNullOrWhiteSpace(si.SubrogationGuiltyPartner))
                                {
                                    Asigurat aRca = new Asigurat(uid, conStr, si.SubrogationGuiltyPartner);
                                    if (aRca == null || aRca.ID == null)
                                    {
                                        aRca          = new Asigurat(uid, conStr);
                                        aRca.DENUMIRE = si.SubrogationGuiltyPartner;
                                        r             = aRca.Insert();
                                    }
                                    d.ID_ASIGURAT_RCA = aRca.ID;
                                }
                            }
                            catch (Exception exp) { LogWriter.Log(exp); }

                            try
                            {
                                if (!String.IsNullOrWhiteSpace(si.InsuredCarPlateNo))
                                {
                                    Auto autoCasco = new Auto(uid, conStr, si.InsuredCarPlateNo);
                                    if (autoCasco == null || autoCasco.ID == null)
                                    {
                                        autoCasco             = new Auto(uid, conStr);
                                        autoCasco.NR_AUTO     = si.InsuredCarPlateNo;
                                        autoCasco.MARCA       = si.InsuredCarBrandName;
                                        autoCasco.MODEL       = si.InsuredCarModelName;
                                        autoCasco.SERIE_SASIU = si.InsuredCarChassisNo;
                                        r = autoCasco.Insert();
                                    }
                                    d.ID_AUTO_CASCO = autoCasco.ID;
                                }
                            }
                            catch (Exception exp) { LogWriter.Log(exp); }

                            try
                            {
                                if (!String.IsNullOrWhiteSpace(si.SubrogationCarPlateNo))
                                {
                                    Auto autoRca = new Auto(uid, conStr, si.SubrogationCarPlateNo);
                                    if (autoRca == null || autoRca.ID == null)
                                    {
                                        autoRca         = new Auto(uid, conStr);
                                        autoRca.NR_AUTO = si.SubrogationCarPlateNo;
                                        //autoRca.MARCA = si.SubrogationCarBrandName;
                                        //autoRca.MODEL = si.SubrogationCarModelName;
                                        autoRca.SERIE_SASIU = si.SubrogationCarChassisNo;
                                        r = autoRca.Insert();
                                    }
                                    d.ID_AUTO_RCA = autoRca.ID;
                                }
                            }
                            catch (Exception exp) { LogWriter.Log(exp); }

                            try { d.CAZ = si.AmiableAssessmentNo; } catch { }
                            try { d.DATA_CREARE = d.DATA_ULTIMEI_MODIFICARI = DateTime.Now; } catch { }
                            try {
                                if (si.LossDate == DateTime.MinValue)
                                {
                                    d.DATA_EVENIMENT = null;
                                }
                                else
                                {
                                    d.DATA_EVENIMENT = si.LossDate;
                                }
                            } catch { }
                            try { d.DATA_NOTIFICARE = si.AssessmentDate; } catch { } //?? - la ei este Data Constatarii, nu cred ca e tot una cu Data Notificarii de la noi
                            try { d.NR_DOSAR_CASCO = si.ClaimFileNo; } catch { }
                            try { d.NR_POLITA_CASCO = si.InsuredPolicyNo; } catch { }
                            try { d.NR_POLITA_RCA = si.SubrogationRcoPolicyNo; } catch { }
                            try { d.SUMA_IBNR = d.VALOARE_DAUNA = d.VALOARE_REGRES = d.VMD = d.REZERVA_DAUNA = Convert.ToDouble(si.ClaimReserveValueRon); } catch { }
                            try { d.LOC_ACCIDENT = String.Format("{0}{1}{2}{3}{4}{5}",
                                                                 si.LossCountry,
                                                                 String.IsNullOrWhiteSpace(si.LossCity) ? "" : ", " + si.LossCity,
                                                                 String.IsNullOrWhiteSpace(si.LossDistrictNo.ToString()) ? "" : ", sector " + si.LossDistrictNo.ToString(),
                                                                 String.IsNullOrWhiteSpace(si.LossStreet) ? "" : ", str. " + si.LossStreet,
                                                                 String.IsNullOrWhiteSpace(si.LossStreetNo) ? "" : ", nr. " + si.LossStreetNo,
                                                                 String.IsNullOrWhiteSpace(si.LossIntersection) ? "" : ", intersectie cu str. " + si.LossIntersection); } catch { }

                            validationResponse = d.Validare();
                            if (validationResponse.Status)
                            {
                                r = d.Insert();
                                validationResponse.InsertedId = r.InsertedId;
                                validationResponse.Status     = true;
                                if (r.Status && r.InsertedId != null)
                                {
                                    d.Log(validationResponse, 1);  // 1 = automatic import
                                    ClaimDocumentSummary[] cdss = s.BrowseClaimDocuments(si.ClaimId, DateTime.MinValue);
                                    foreach (ClaimDocumentSummary cds in cdss)
                                    {
                                        try
                                        {
                                            //TipDocument td = new TipDocument(uid, conStr, cds.CategoryName);
                                            TipDocument td         = null;
                                            int?        id_tip_doc = GetTipDocumentMapping(TipuriDocumentMappings, cds.CategoryId);
                                            if (id_tip_doc != null && id_tip_doc != 0)
                                            {
                                                td = new TipDocument(uid, conStr, Convert.ToInt32(id_tip_doc));
                                            }

                                            DocumentScanat ds = new DocumentScanat(uid, conStr);
                                            ds.DENUMIRE_FISIER = String.IsNullOrWhiteSpace(cds.Name) ? cds.FileName : cds.Name;
                                            ds.EXTENSIE_FISIER = !String.IsNullOrWhiteSpace(cds.Extension) ? cds.Extension : !String.IsNullOrWhiteSpace(cds.Name) ? cds.Name.Substring(cds.Name.LastIndexOf('.')) : cds.FileName.Substring(cds.FileName.LastIndexOf('.'));
                                            ds.ID_TIP_DOCUMENT = Convert.ToInt32(td.ID);
                                            ds.ID_DOSAR        = Convert.ToInt32(d.ID);

                                            BinaryContent bc = s.GetClaimDocumentDetails(cds.Id);
                                            ds.FILE_CONTENT = bc.BinaryData;

                                            ds.CALE_FISIER = FileManager.SaveBinaryContentToFile(bc.BinaryData, ds.EXTENSIE_FISIER);

                                            response rd = ds.Validare();
                                            if (rd.Status)
                                            {
                                                rd = ds.Insert();
                                                ds.Log(rd, 1); // 1 = automatic import
                                            }
                                            if (!rd.Status)    // marcam dosarul ca citit (preluat) de la Allianz doar daca s-a reusit preluarea tuturor documentelor asociate
                                            {
                                                r.AddResponse(rd);
                                            }
                                        }
                                        catch (Exception exp) {
                                            LogWriter.Log(exp);
                                            r.AddResponse(new response(false, exp.ToString(), null, null, new List <Error>()
                                            {
                                                new Error(exp)
                                            }));
                                        }
                                    }

                                    if (r.Status)
                                    {
                                        if (!WithoutMarkings)
                                        {
                                            s.MarkAsReadByClaimId(si.ClaimId);
                                        }
                                        if (WithoutEmails && WithPdfs)
                                        {
                                            d.GenerateNotificarePdf();
                                        }
                                        if (!WithoutEmails)
                                        {
                                            d.SendNotificare(EmailProfiles.AwsNotificariSES);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                r = d.InsertWithErrors();
                                validationResponse.Status     = false;
                                validationResponse.InsertedId = r.InsertedId;
                                if (r.Status && r.InsertedId != null)
                                {
                                    d.Log(validationResponse, 1); // 1 = automatic import
                                    ClaimDocumentSummary[] cdss = s.BrowseClaimDocuments(si.ClaimId, DateTime.MinValue);
                                    foreach (ClaimDocumentSummary cds in cdss)
                                    {
                                        try
                                        {
                                            //TipDocument td = new TipDocument(uid, conStr, cds.CategoryName);
                                            TipDocument td         = null;
                                            int?        id_tip_doc = GetTipDocumentMapping(TipuriDocumentMappings, cds.CategoryId);
                                            if (id_tip_doc != null && id_tip_doc != 0)
                                            {
                                                td = new TipDocument(uid, conStr, Convert.ToInt32(id_tip_doc));
                                            }

                                            DocumentScanat ds = new DocumentScanat(uid, conStr);
                                            ds.DENUMIRE_FISIER = String.IsNullOrWhiteSpace(cds.Name) ? cds.FileName : cds.Name;
                                            ds.EXTENSIE_FISIER = !String.IsNullOrWhiteSpace(cds.Extension) ? cds.Extension : !String.IsNullOrWhiteSpace(cds.Name) ? cds.Name.Substring(cds.Name.LastIndexOf('.')) : cds.FileName.Substring(cds.FileName.LastIndexOf('.'));
                                            ds.ID_TIP_DOCUMENT = Convert.ToInt32(td.ID);
                                            ds.ID_DOSAR        = Convert.ToInt32(d.ID);

                                            BinaryContent bc = s.GetClaimDocumentDetails(cds.Id);
                                            ds.FILE_CONTENT = bc.BinaryData;

                                            ds.CALE_FISIER = FileManager.SaveBinaryContentToFile(bc.BinaryData, ds.EXTENSIE_FISIER);

                                            response rd = ds.Validare();
                                            if (rd.Status)
                                            {
                                                rd = ds.InsertWithErrors();
                                                ds.Log(rd, 1); // 1 = automatic import
                                            }
                                            if (!rd.Status)    // marcam dosarul ca citit (preluat) de la Allianz doar daca s-a reusit preluarea tuturor documentelor asociate
                                            {
                                                r.AddResponse(rd);
                                            }
                                        }
                                        catch (Exception exp) {
                                            LogWriter.Log(exp);
                                            r.AddResponse(new response(false, exp.ToString(), null, null, new List <Error>()
                                            {
                                                new Error(exp)
                                            }));
                                        }
                                    }

                                    if (r.Status)
                                    {
                                        if (!WithoutMarkings)
                                        {
                                            s.MarkAsReadByClaimId(si.ClaimId);
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception exp) { LogWriter.Log(exp); }
                        counter++;
                    }
                }
            }
            catch (Exception exp)
            {
                LogWriter.Log(exp);
            }
        }
예제 #9
0
파일: Program.cs 프로젝트: andpsy/socisaV2
        // Process all files in the directory passed in, recurse on any directories
        // that are found, and process the files they contain.
        public static void ProcessDirectory(string targetDirectory, SOCISA.Models.Dosar dosar)
        {
            string   conStr          = CommonFunctions.StringCipher.Decrypt(ConfigurationManager.ConnectionStrings["MySqlConnectionString"].ToString(), CommonFunctions.StringCipher.RetrieveKey());
            int      _CURENT_USER_ID = 1;
            response r        = new response();
            string   LOG_FILE = "c:\\Uploads\\Log.txt";

            try
            {
                // Recurse into subdirectories of this directory.
                string[] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
                if (DocumenteAll)
                {
                    foreach (string subdirectory in subdirectoryEntries)
                    {
                        if (subdirectory.ToUpper().Substring(subdirectory.LastIndexOf('\\') + 1) == dosar.NR_DOSAR_CASCO.ToUpper())
                        {
                            try
                            {
                                //incarcam documentele
                                string[] docs = Directory.GetFiles(subdirectory, "*.*", SearchOption.AllDirectories);

                                /*
                                 * StreamWriter sss = File.AppendText(dosar.NR_DOSAR_CASCO + "_docs.txt");
                                 * foreach (string f in docs)
                                 * {
                                 *  sss.Write(String.Format("{0}\r\n", f));
                                 * }
                                 * sss.Flush(); sss.Dispose();
                                 */
                                TipDocument td = new TipDocument(_CURENT_USER_ID, conStr, "ALTE INSCRISURI");
                                foreach (string fileName in docs)
                                {
                                    try
                                    {
                                        DocumentScanat ods = new DocumentScanat(_CURENT_USER_ID, conStr, fileName.Substring(fileName.LastIndexOf('\\') + 1), Convert.ToInt32(dosar.ID));
                                        if (ods != null && ods.ID != null) // exista deja documentul in bd
                                        {
                                            Console.Write(String.Format("{0} - {1} exista deja in baza de date!", dosar.NR_DOSAR_CASCO, fileName));
                                            StreamWriter sw = File.AppendText(LOG_FILE);
                                            sw.Write(String.Format("{0} - {1} exista deja in baza de date!\r\n", dosar.NR_DOSAR_CASCO, fileName));
                                            sw.Flush(); sw.Dispose();
                                        }
                                        else
                                        {
                                            string newFName = FileManager.CopyFileToServer(fileName);
                                            if (newFName != null)
                                            {
                                                DocumentScanat ds = new DocumentScanat(_CURENT_USER_ID, conStr);
                                                ds.CALE_FISIER     = newFName;
                                                ds.DENUMIRE_FISIER = fileName.Substring(fileName.LastIndexOf('\\') + 1);
                                                ds.ID_TIP_DOCUMENT = Convert.ToInt32(td.ID);
                                                ds.ID_DOSAR        = Convert.ToInt32(dosar.ID);
                                                r = ds.Insert();
                                                if (r.Status)
                                                {
                                                    Console.Write(String.Format("{0} - {1} importat!", dosar.NR_DOSAR_CASCO, fileName));
                                                    StreamWriter sw = File.AppendText(LOG_FILE);
                                                    sw.Write(String.Format("{0} - {1} importat!\r\n", dosar.NR_DOSAR_CASCO, fileName));
                                                    sw.Flush(); sw.Dispose();
                                                }
                                                else
                                                {
                                                    Console.Write(String.Format("{0} - {1} eroare, {2}!", dosar.NR_DOSAR_CASCO, fileName, r.Message));
                                                    StreamWriter sw = File.AppendText(LOG_FILE);
                                                    sw.Write(String.Format("{0} - {1} eroare, {2}!", dosar.NR_DOSAR_CASCO, fileName, r.Message));
                                                    sw.Flush(); sw.Dispose();
                                                }
                                            }
                                        }
                                    }
                                    catch (Exception exp) { LogWriter.Log(exp); }
                                }
                            }
                            catch (Exception exp) { LogWriter.Log(exp); }
                        }
                        ProcessDirectory(subdirectory, dosar);
                    }
                }
                else
                {
                    foreach (string subdirectory in subdirectoryEntries)
                    {
                        if (subdirectory.ToUpper().Substring(subdirectory.LastIndexOf('\\') + 1) == String.Format("{0} DOC", dosar.NR_DOSAR_CASCO.ToUpper()))
                        {
                            try
                            {
                                //incarcam documentele
                                string[]    docs = Directory.GetFiles(subdirectory);
                                TipDocument td   = new TipDocument(_CURENT_USER_ID, conStr, "ALTE INSCRISURI");
                                foreach (string fileName in docs)
                                {
                                    try
                                    {
                                        DocumentScanat ods = new DocumentScanat(_CURENT_USER_ID, conStr, fileName.Substring(fileName.LastIndexOf('\\') + 1), Convert.ToInt32(dosar.ID));
                                        if (ods != null && ods.ID != null) // exista deja documentul in bd
                                        {
                                            Console.Write(String.Format("{0} - {1} exista deja in baza de date!", dosar.NR_DOSAR_CASCO, fileName));
                                            StreamWriter sw = File.AppendText(LOG_FILE);
                                            sw.Write(String.Format("{0} - {1} exista deja in baza de date!\r\n", dosar.NR_DOSAR_CASCO, fileName));
                                            sw.Flush(); sw.Dispose();
                                        }
                                        else
                                        {
                                            string newFName = FileManager.CopyFileToServer(fileName);
                                            if (newFName != null)
                                            {
                                                DocumentScanat ds = new DocumentScanat(_CURENT_USER_ID, conStr);
                                                ds.CALE_FISIER     = newFName;
                                                ds.DENUMIRE_FISIER = fileName.Substring(fileName.LastIndexOf('\\') + 1);
                                                ds.ID_TIP_DOCUMENT = Convert.ToInt32(td.ID);
                                                ds.ID_DOSAR        = Convert.ToInt32(dosar.ID);
                                                r = ds.Insert();
                                                if (r.Status)
                                                {
                                                    Console.Write(String.Format("{0} - {1} importat!", dosar.NR_DOSAR_CASCO, fileName));
                                                    StreamWriter sw = File.AppendText(LOG_FILE);
                                                    sw.Write(String.Format("{0} - {1} importat!\r\n", dosar.NR_DOSAR_CASCO, fileName));
                                                    sw.Flush(); sw.Dispose();
                                                }
                                                else
                                                {
                                                    Console.Write(String.Format("{0} - {1} eroare, {2}!", dosar.NR_DOSAR_CASCO, fileName, r.Message));
                                                    StreamWriter sw = File.AppendText(LOG_FILE);
                                                    sw.Write(String.Format("{0} - {1} eroare, {2}!", dosar.NR_DOSAR_CASCO, fileName, r.Message));
                                                    sw.Flush(); sw.Dispose();
                                                }
                                            }
                                        }
                                    }
                                    catch (Exception exp) { LogWriter.Log(exp); }
                                }
                            }
                            catch (Exception exp) { LogWriter.Log(exp); }
                        }

                        if (subdirectory.ToUpper().Substring(subdirectory.LastIndexOf('\\') + 1) == String.Format("{0} PLANSE", dosar.NR_DOSAR_CASCO.ToUpper()))
                        {
                            try
                            {
                                //incarcam plansele
                                string[]    docs = Directory.GetFiles(subdirectory);
                                TipDocument td   = new TipDocument(_CURENT_USER_ID, conStr, "FOTOGRAFII DE CONSTATARE");
                                foreach (string fileName in docs)
                                {
                                    try
                                    {
                                        DocumentScanat ods = new DocumentScanat(_CURENT_USER_ID, conStr, fileName.Substring(fileName.LastIndexOf('\\') + 1), Convert.ToInt32(dosar.ID));
                                        if (ods != null && ods.ID != null) // exista deja documentul in bd
                                        {
                                            Console.Write(String.Format("{0} - {1} exista deja in baza de date!", dosar.NR_DOSAR_CASCO, fileName));
                                            StreamWriter sw = File.AppendText(LOG_FILE);
                                            sw.Write(String.Format("{0} - {1} exista deja in baza de date!\r\n", dosar.NR_DOSAR_CASCO, fileName));
                                            sw.Flush(); sw.Dispose();
                                        }
                                        else
                                        {
                                            string newFName = FileManager.CopyFileToServer(fileName);
                                            if (newFName != null)
                                            {
                                                DocumentScanat ds = new DocumentScanat(_CURENT_USER_ID, conStr);
                                                ds.CALE_FISIER     = newFName;
                                                ds.DENUMIRE_FISIER = fileName.Substring(fileName.LastIndexOf('\\') + 1);
                                                ds.ID_TIP_DOCUMENT = Convert.ToInt32(td.ID);
                                                ds.ID_DOSAR        = Convert.ToInt32(dosar.ID);
                                                r = ds.Insert();
                                                if (r.Status)
                                                {
                                                    Console.Write(String.Format("{0} - {1} importat!", dosar.NR_DOSAR_CASCO, fileName));
                                                    StreamWriter sw = File.AppendText(LOG_FILE);
                                                    sw.Write(String.Format("{0} - {1} importat!\r\n", dosar.NR_DOSAR_CASCO, fileName));
                                                    sw.Flush(); sw.Dispose();
                                                }
                                                else
                                                {
                                                    Console.Write(String.Format("{0} - {1} eroare, {2}!", dosar.NR_DOSAR_CASCO, fileName, r.Message));
                                                    StreamWriter sw = File.AppendText(LOG_FILE);
                                                    sw.Write(String.Format("{0} - {1} eroare, {2}!", dosar.NR_DOSAR_CASCO, fileName, r.Message));
                                                    sw.Flush(); sw.Dispose();
                                                }
                                            }
                                        }
                                    }
                                    catch (Exception exp) { LogWriter.Log(exp); }
                                }
                            }
                            catch (Exception exp) { LogWriter.Log(exp); }
                        }
                        ProcessDirectory(subdirectory, dosar);
                    }
                }
            }
            catch (Exception exp)
            {
                LogWriter.Log(exp);
            }
        }
예제 #10
0
        public ActionResult Create(HttpPostedFileBase file, int?categoryId, string name)
        {
            if (categoryId == null)
            {
                TempData["ErrorMessage"] = "Category required. Re-enter all.";
                return(RedirectToAction("Create"));
            }

            try
            {
                if (file != null)
                {
                    var    fileName = Path.GetFileName(file.FileName);
                    string path     = Server.MapPath(" ") + "\\" + fileName;
                    path = path.Replace("\\TipDocuments", "\\UploadFiles");
                    path = path.Replace("\\", "/");
                    file.SaveAs(path);

                    CloudStorageAccount storageAccount =
                        CloudStorageAccount.Parse(Settings.Default.StorageConnectionString);
                    CloudBlobClient    blobClient = storageAccount.CreateCloudBlobClient();
                    CloudBlobContainer container  = blobClient.GetContainerReference("teachingtips");
                    CloudBlockBlob     blob       = container.GetBlockBlobReference(fileName);

                    if (blob.Exists())
                    {
                        TempData["ErrorMessage"] = "There is already a file with this name. Re-enter all.";
                        return(RedirectToAction("Create"));
                    }

                    if (fileName != null && fileName.ToUpper().Substring(fileName.Length - 3, 3) == "MP4")
                    {
                        blob.Properties.ContentType = "video/mp4";
                    }
                    else
                    {
                        blob.Properties.ContentType = "application/pdf";
                    }

                    using (var fileStream = System.IO.File.OpenRead(path))
                    {
                        blob.UploadFromStream(fileStream);
                    }

                    System.IO.File.Delete(path);

                    int i = path.IndexOf("UploadFiles", StringComparison.Ordinal);
                    path = path.Remove(0, i + 12);

                    string currentUserId = User.Identity.GetUserId();
                    var    tipDocument   = new TipDocument
                    {
                        DocumentLink = path.Replace(@"\", "/"),
                        User         = _db.Users.Find(currentUserId),
                        Category     = _db.TipsCategories.Find(categoryId),
                        Name         = name
                    };
                    _db.TipDocuments.Add(tipDocument);
                    _db.SaveChanges();

                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception)
            {
                return(null);
            }
            TempData["ErrorMessage"] = "File not found error.";
            return(RedirectToAction("Create"));
        }
예제 #11
0
 public TipDocumentJson(TipDocument td, DocumentScanat[] dss)
 {
     this.TipDocument      = td;
     this.DocumenteScanate = dss;
 }