Example #1
0
 public IHttpActionResult DeletePurchaseOrderFile(Object obj)
 {
     try
     {
         JObject json = JObject.Parse(obj.ToString());
         Bis.PurchaseOrderFileMethod    BisPurchaseOrderFile = new Bis.PurchaseOrderFileMethod();
         ViewModel.tblPurchaseOrderFile delete = new ViewModel.tblPurchaseOrderFile();
         delete.IDPurchaseOrderFile = json["IDPurchaseOrderFile"].ToString().StringToGuid();
         bool ret = BisPurchaseOrderFile.DeletePurchaseOrderFile(delete);
         if (ret)
         {
             File.Delete(AppDomain.CurrentDomain.BaseDirectory + json["FileUrl"].ToString());
             return(Ok(ret));
         }
         else
         {
             return(NotFound());
         }
     }
     catch
     {
         return(NotFound());
     }
 }
Example #2
0
        public IHttpActionResult AddPurchaseOrderFile()
        {
            AuthorizationUser AuUser = new AuthorizationUser();

            Bis.PurchaseOrderFileMethod BisPurchaseOrderFile = new Bis.PurchaseOrderFileMethod();

            try
            {
                var    File                   = HttpContext.Current.Request.Files["excelFileUpload"];
                string FileType               = File.FileName.Substring(File.FileName.LastIndexOf("."));
                var    IDPurchaseOrderFile    = HttpContext.Current.Request["IDPurchaseOrderFile"];
                var    IDLogUser              = HttpContext.Current.Request["IDLogUser"];
                var    TitlePurchaseOrderFile = HttpContext.Current.Request["TitlePurchaseOrderFile"];
                var    IDSupplier             = HttpContext.Current.Request["IDSupplier"];
                var    IDCurrency             = HttpContext.Current.Request["IDCurrency"];
                var    DeliverDate            = HttpContext.Current.Request["DeliverDate"];
                var    ExcelJson              = HttpContext.Current.Request["ExcelJson"];

                ViewModel.tblPurchaseOrderFile Add = new ViewModel.tblPurchaseOrderFile();
                Add.IDPurchaseOrderFile = IDPurchaseOrderFile.ToString().StringToGuid();
                Add.IDPersonel          = AuUser.ReturnIDUser(IDLogUser.ToString().StringToGuid());
                Add.IDSupplier          = IDSupplier.ToString().StringToGuid();
                Add.IDCurrency          = IDCurrency.ToString().StringToGuid();
                Add.Title = TitlePurchaseOrderFile.ToString();
                if (DeliverDate == "undefined")
                {
                    Add.DeliverDate = "";
                }
                else
                {
                    Add.DeliverDate = DeliverDate.ToString();
                }

                Add.FileSize  = File.ContentLength; //byte
                Add.FileUrl   = @"File\AttachCrm\" + Add.IDPurchaseOrderFile + "@" + File.FileName;
                Add.ExcelJson = ExcelJson.ToString();
                bool ret = BisPurchaseOrderFile.AddPurchaseOrderFile(Add);
                if (ret)
                {
                    try
                    {
                        File.SaveAs(AppDomain.CurrentDomain.BaseDirectory + Add.FileUrl);
                        return(Ok(ret));
                    }
                    catch (Exception)
                    {
                        ViewModel.tblPurchaseOrderFile delete = new ViewModel.tblPurchaseOrderFile();
                        delete.IDPurchaseOrderFile = Add.IDPurchaseOrderFile;
                        bool ret2 = BisPurchaseOrderFile.DeletePurchaseOrderFile(delete);
                        return(NotFound());
                    }
                }
                else
                {
                    return(NotFound());
                }
            }
            catch
            {
                return(NotFound());
            }
        }