Esempio n. 1
0
 public ActionResult Delete(string data)
 {
     using (var dbConn = Helpers.OrmliteConnection.openConn())
         using (var dbTrans = dbConn.OpenTransaction(IsolationLevel.ReadCommitted))
             if (asset.Delete)
             {
                 try
                 {
                     string[] separators = { "@@" };
                     var      listRowID  = data.Split(separators, StringSplitOptions.RemoveEmptyEntries);
                     var      delete     = new CRM_PageProduct();
                     foreach (var item in listRowID)
                     {
                         delete.ProductID = Int32.Parse(item);
                         dbConn.Delete(delete);
                     }
                     dbTrans.Commit();
                 }
                 catch (Exception ex)
                 {
                     return(Json(new { success = false, alert = ex.Message }));
                 }
                 return(Json(new { success = true }));
             }
             else
             {
                 return(Json(new { success = false, alert = "You don't have permission to delete record" }));
             }
 }
Esempio n. 2
0
        public ActionResult UpdateDetail([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")] IEnumerable <CRM_PageProduct> list)
        {
            var dbConn = Helpers.OrmliteConnection.openConn();

            if (asset.Create || asset.Update)
            {
                if (list != null)
                {
                    try
                    {
                        foreach (var item in list)
                        {
                            var exits = dbConn.SingleOrDefault <CRM_PageProduct>("PositionID= {0}", item.PositionID);
                            if (exits == null)
                            {
                                var row = new CRM_PageProduct();
                                row.ProductName = !string.IsNullOrEmpty(item.ProductName) ? item.ProductName.Trim() : "";
                                row.ProductType = !string.IsNullOrEmpty(item.ProductType) ? item.ProductType.Trim() : "";
                                row.PositionID  = !(item.PositionID == 0) ? item.PositionID : 0;
                                row.CategoryID  = !(item.CategoryID == 0) ? item.CategoryID : 0;
                                row.Price       = !(item.Price == 0) ? item.Price : 0;
                                row.PriceType   = !string.IsNullOrEmpty(item.PriceType) ? item.PriceType.Trim() : "";
                                row.Status      = !(item.Status == 0) ? item.Status : 0;

                                row.CreatedBy = currentUser.UserName;
                                row.UpdatedBy = "";
                                row.CreatedAt = DateTime.Now;
                                row.UpdatedAt = DateTime.Parse("1900-01-01");
                                dbConn.Insert(row);
                            }
                            else
                            {
                                exits.ProductName = !string.IsNullOrEmpty(item.ProductName) ? item.ProductName.Trim() : "";
                                exits.ProductType = !string.IsNullOrEmpty(item.ProductType) ? item.ProductType.Trim() : "";
                                exits.PositionID  = !(item.PositionID == 0) ? item.PositionID : 0;
                                exits.CategoryID  = !(item.CategoryID == 0) ? item.CategoryID : 0;
                                exits.Price       = !(item.Price == 0) ? item.Price : 0;
                                exits.PriceType   = !string.IsNullOrEmpty(item.PriceType) ? item.PriceType.Trim() : "";
                                exits.Status      = !(item.Status == 0) ? item.Status : 0;

                                exits.UpdatedBy = currentUser.UserName;
                                exits.UpdatedAt = DateTime.Now;
                                dbConn.Update(exits);
                            }
                        }
                        ModelState.AddModelError("Thành công!", "Lưu thành công.");
                        return(Json(new { sussess = true }));
                    }
                    catch (Exception ex)
                    {
                        ModelState.AddModelError("error", ex.Message);
                        return(Json(list.ToDataSourceResult(request, ModelState)));
                    }
                }
                return(Json(new { sussess = true }));
            }

            else
            {
                ModelState.AddModelError("error", "Bạn không có quyền cập nhật.");
                return(Json(list.ToDataSourceResult(request, ModelState)));
            }
        }