Exemplo n.º 1
0
 public IHttpActionResult DeleteQouationFile(Object obj)
 {
     try
     {
         JObject json = JObject.Parse(obj.ToString());
         Bis.QouationFileMethod    BisQouation = new Bis.QouationFileMethod();
         ViewModel.tblQouationFile delete      = new ViewModel.tblQouationFile();
         delete.IDQouationFile = json["IDQouationFile"].ToString().StringToGuid();
         bool ret = BisQouation.DeleteQouationFile(delete);
         if (ret)
         {
             if (json["FileUrlExcel"] != null)
             {
                 File.Delete(AppDomain.CurrentDomain.BaseDirectory + json["FileUrlExcel"].ToString());
             }
             if (json["FileUrlEmail"] != null)
             {
                 File.Delete(AppDomain.CurrentDomain.BaseDirectory + json["FileUrlEmail"].ToString());
             }
             File.Delete(AppDomain.CurrentDomain.BaseDirectory + json["FileUrlPdf"].ToString());
             return(Ok(ret));
         }
         else
         {
             return(NotFound());
         }
     }
     catch
     {
         return(NotFound());
     }
 }
Exemplo n.º 2
0
        public IHttpActionResult AddQouationFile()
        {
            AuthorizationUser AuUser = new AuthorizationUser();

            Bis.QouationFileMethod BisQouation = new Bis.QouationFileMethod();

            try
            {
                ViewModel.tblQouationFile Add = new ViewModel.tblQouationFile();
                bool ExcelModeQouation        = HttpContext.Current.Request["ExcelModeQouation"].ToString().StringToBool();

                var PdfFile        = HttpContext.Current.Request.Files["pdfFileUploadQouation"];
                var IDQouationFile = HttpContext.Current.Request["IDQouationFile"];
                var IDLogUser      = HttpContext.Current.Request["IDLogUser"];
                var TitleQouation  = HttpContext.Current.Request["TitleQouation"];
                var IDSupplier     = HttpContext.Current.Request["IDSupplier"];
                var IDCurrency     = HttpContext.Current.Request["IDCurrency"];
                var OrigDate       = HttpContext.Current.Request["OrigDate"];
                var EmailFile      = HttpContext.Current.Request.Files["EmailFileUploadQouation"];



                Add.IDQouationFile = IDQouationFile.ToString().StringToGuid();
                Add.IDPersonel     = AuUser.ReturnIDUser(IDLogUser.ToString().StringToGuid());
                Add.IDSupplier     = IDSupplier.ToString().StringToGuid();
                Add.IDCurrency     = IDCurrency.ToString().StringToGuid();
                Add.Title          = TitleQouation.ToString();
                Add.OrigDate       = OrigDate.ToString().StringToDateTime();

                Add.FileSizePdf = PdfFile.ContentLength; //byte
                Add.FileUrlPdf  = @"File\AttachCrm\" + Add.IDQouationFile + "@" + PdfFile.FileName;

                if (EmailFile != null)
                {
                    Add.FileSizeEmail = EmailFile.ContentLength; //byte
                    Add.FileUrlEmail  = @"File\AttachCrm\" + Add.IDQouationFile + "@" + EmailFile.FileName;
                }
                bool ret = false;
                if (ExcelModeQouation)
                {
                    var ExcelFile         = HttpContext.Current.Request.Files["excelFileUploadQouation"];
                    var ExcelJsonQouation = HttpContext.Current.Request["ExcelJsonQouation"];
                    Add.FileSizeExcel     = ExcelFile.ContentLength; //byte
                    Add.FileUrlExcel      = @"File\AttachCrm\" + Add.IDQouationFile + "@" + ExcelFile.FileName;
                    Add.ExcelJsonQouation = ExcelJsonQouation.ToString();
                    Add.ExcelMode         = true;
                    ret = BisQouation.AddQouationFileWithExcel(Add);
                    if (ret)
                    {
                        try
                        {
                            ExcelFile.SaveAs(AppDomain.CurrentDomain.BaseDirectory + Add.FileUrlExcel);
                            PdfFile.SaveAs(AppDomain.CurrentDomain.BaseDirectory + Add.FileUrlPdf);
                            if (EmailFile != null)
                            {
                                EmailFile.SaveAs(AppDomain.CurrentDomain.BaseDirectory + Add.FileUrlEmail);
                            }
                            return(Ok(ret));
                        }
                        catch (Exception)
                        {
                            ViewModel.tblQouationFile delete = new ViewModel.tblQouationFile();
                            delete.IDQouationFile = Add.IDQouationFile;
                            bool ret2 = BisQouation.DeleteQouationFile(delete);
                            return(NotFound());
                        }
                    }
                    else
                    {
                        return(NotFound());
                    }
                }
                else
                {
                    Add.ExcelMode = false;
                    ret           = BisQouation.AddQouationFileWithOutExcel(Add);
                    if (ret)
                    {
                        try
                        {
                            PdfFile.SaveAs(AppDomain.CurrentDomain.BaseDirectory + Add.FileUrlPdf);
                            if (EmailFile != null)
                            {
                                EmailFile.SaveAs(AppDomain.CurrentDomain.BaseDirectory + Add.FileUrlEmail);
                            }
                            return(Ok(ret));
                        }
                        catch (Exception)
                        {
                            ViewModel.tblQouationFile delete = new ViewModel.tblQouationFile();
                            delete.IDQouationFile = Add.IDQouationFile;
                            bool ret2 = BisQouation.DeleteQouationFile(delete);
                            return(NotFound());
                        }
                    }
                    else
                    {
                        return(NotFound());
                    }
                }
            }
            catch
            {
                return(NotFound());
            }
        }