Пример #1
0
 public string UpSert(Merchant_Catalog catalog, string UserName, string connectionString)
 {
     using (var db = new OrmliteConnection().openConn(connectionString))
     {
         try
         {
             var checkID = db.SingleOrDefault <Merchant_Catalog>("id={0}", catalog.id);
             if (checkID != null)
             {
                 catalog.ngay_cap_nhat  = DateTime.Now;
                 catalog.nguoi_cap_nhat = UserName;
                 catalog.nguoi_tao      = checkID.nguoi_tao;
                 catalog.ngay_tao       = checkID.ngay_tao;
                 db.Update(catalog);
             }
             else
             {
                 catalog.nguoi_tao      = UserName;
                 catalog.nguoi_cap_nhat = UserName;
                 catalog.ngay_tao       = DateTime.Now;
                 catalog.ngay_cap_nhat  = DateTime.Now;
                 var lastId = db.FirstOrDefault <Merchant_Catalog>("SELECT TOP 1 * FROM Merchant_Catalog ORDER BY id DESC");
                 if (lastId != null)
                 {
                     if (lastId.ma_catalog.Contains("CAT"))
                     {
                         var nextNo = Int32.Parse(lastId.ma_catalog.Substring(3, 10)) + 1;
                         catalog.ma_catalog = "CAT" + String.Format("{0:0000000000}", nextNo);
                     }
                 }
                 else
                 {
                     catalog.ma_catalog = "CAT" + "0000000001";
                 }
                 db.Insert(catalog);
             }
             return("true");
         }
         catch (Exception e)
         {
             return(e.Message.ToString());
         }
     }
 }
Пример #2
0
        public ActionResult Save(List <HttpPostedFileBase> files)
        {
            try
            {
                int i = 0;
                Merchant_Folder_Info folder = new Merchant_Folder_Info();
                folder.ma_gian_hang   = currentUser.ma_gian_hang;
                folder.ten_thu_muc    = AllConstant.FoldderName_Merchant_Catalog;
                folder.ngay_tao       = DateTime.Now;
                folder.nguoi_tao      = currentUser.name;
                folder.ngay_cap_nhat  = DateTime.Now;
                folder.nguoi_cap_nhat = currentUser.name;
                string a = new Merchant_Folder_Info_DAO().Insert(folder, AppConfigs.MCCConnectionString);
                foreach (var item in files)
                {
                    string LocalPath       = "";
                    string LocalFolderPath = "";
                    string url_link        = new AzureHelper().UploadFileToAzure("Catalog", item, currentUser.name, ref LocalFolderPath, ref LocalPath);
                    //update catalog info
                    Merchant_Catalog catalog = new Merchant_Catalog();
                    catalog.dung_luong       = item.ContentLength;
                    catalog.duong_dan_day_du = url_link;
                    catalog.ma_gian_hang     = currentUser.ma_gian_hang;
                    catalog.ten_catalog      = Path.GetFileNameWithoutExtension(item.FileName);
                    catalog.thu_muc          = LocalFolderPath;
                    catalog.url = DateTime.Now.ToString("yyyyMMddHHmmssfff") + currentUser.name + "-" + item.FileName;
                    string b = new Merchant_Catalog_DAO().UpSert(catalog, currentUser.name, AppConfigs.MCCConnectionString);

                    if (!string.IsNullOrEmpty(url_link))
                    {
                        i++;
                    }
                }
                return(Json(new { success = true, message = "Upload thành công " + i.ToString() + " file!" }));
            }
            catch (Exception e)
            {
                return(Json(new { success = false, message = e.Message }));
            }
        }