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 DC_Telesales_ManageInfo();
                     foreach (var item in listRowID)
                     {
                         delete.ID = 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" }));
             }
 }
 public ActionResult DailyNew_Create([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]  IEnumerable <DC_Telesales_ManageInfo> list)
 {
     using (var dbConn = Helpers.OrmliteConnection.openConn())
         using (var dbTrans = dbConn.OpenTransaction(IsolationLevel.ReadCommitted))
             if (asset.Create)
             {
                 try
                 {
                     if (list != null && ModelState.IsValid)
                     {
                         var data = new DC_Telesales_ManageInfo();
                         foreach (var item in list)
                         {
                             if (String.IsNullOrEmpty(item.Title))
                             {
                                 ModelState.AddModelError("", "Please input Title");
                                 return(Json(list.ToDataSourceResult(request, ModelState)));
                             }
                             if (String.IsNullOrEmpty(item.Content))
                             {
                                 ModelState.AddModelError("", "Please input Content");
                                 return(Json(list.ToDataSourceResult(request, ModelState)));
                             }
                             data.Title     = item.Title.Trim();
                             data.Content   = item.Content.Trim();
                             data.IsActive  = item.IsActive;
                             data.CreatedAt = DateTime.Now;
                             data.CreatedBy = currentUser.UserName;
                             dbConn.Insert(data);
                         }
                         dbTrans.Commit();
                     }
                 }
                 catch (Exception e)
                 {
                     ModelState.AddModelError("error", e.Message);
                     dbTrans.Rollback();
                     return(Json(list.ToDataSourceResult(request, ModelState)));
                 }
                 return(Json(new { sussess = true }));
             }
             else
             {
                 ModelState.AddModelError("", "You don't have permission to create record");
                 dbTrans.Rollback();
                 return(Json(list.ToDataSourceResult(request, ModelState)));
             }
 }
        public ActionResult Edit(DC_Telesales_ManageInfo article)
        {
            using (var dbConn = Helpers.OrmliteConnection.openConn())
                using (var dbTrans = dbConn.OpenTransaction(IsolationLevel.ReadCommitted))
                    if (asset.Update && ModelState.IsValid)
                    {
                        try
                        {
                            var CheckExit = dbConn.FirstOrDefault <DC_Telesales_ManageInfo>("ID =" + article.ID);
                            if (CheckExit == null)
                            {
                                return(Json(new { error = true, message = "Không tìm thấy." }));
                            }
                            article.CreatedAt = CheckExit.CreatedAt;
                            article.CreatedBy = CheckExit.CreatedBy;
                            article.UpdatedAt = DateTime.Now;
                            article.UpdatedBy = currentUser.UserName;
                            dbConn.Update(article);
                            dbTrans.Commit();
                            return(Json(new { error = false, message = "Thành công." }));
                        }
                        catch (Exception ex)
                        {
                            dbTrans.Rollback();
                            return(Json(new { error = true, message = ex.Message }));
                        }
                    }
                    else
                    {
                        if (!asset.Update)
                        {
                            return(Json(new { error = true, message = "Không có quyền tạo mới." }));
                        }
                        string message = "";
                        foreach (ModelState modelState in ViewData.ModelState.Values)
                        {
                            foreach (ModelError error in modelState.Errors)
                            {
                                message += error.ErrorMessage + " ";
                            }
                        }
                        return(Json(new { error = true, message = message }));
                    }

            return(Json(new { success = true }));
        }
        public ActionResult Create(DC_Telesales_ManageInfo newManageInfo)
        {
            using (var dbConn = Helpers.OrmliteConnection.openConn())
                using (var dbTrans = dbConn.OpenTransaction(IsolationLevel.ReadCommitted))
                    if (asset.Create && ModelState.IsValid)
                    {
                        try
                        {
                            //var formats = new[] { "MM/dd/yyyy HH:mm", "MM-dd-yyyy HH:mm" };
                            newManageInfo.CreatedAt = DateTime.Now;
                            newManageInfo.CreatedBy = currentUser.UserName;
                            //article.StartDate = DateTime.Parse("1900-01-01");
                            //article.ExpiredDate = DateTime.Parse("1900-01-01");
                            newManageInfo.UpdatedAt = DateTime.Now;
                            newManageInfo.UpdatedBy = currentUser.UserName;

                            //string StartDateTime = article.StartDate.ToString(); ;
                            dbConn.Insert(newManageInfo);
                            dbTrans.Commit();
                            return(Json(new { error = false, message = "Thành công" }));
                        }
                        catch (Exception ex)
                        {
                            dbTrans.Rollback();
                            return(Json(new { error = true, message = ex.Message }));
                        }
                    }
                    else
                    {
                        if (!asset.Create)
                        {
                            return(Json(new { error = true, message = "Không có quyền tạo mới." }));
                        }
                        string message = "";
                        foreach (ModelState modelState in ViewData.ModelState.Values)
                        {
                            foreach (ModelError error in modelState.Errors)
                            {
                                message += error.ErrorMessage + " ";
                            }
                        }
                        return(Json(new { error = true, message = message }));
                    }
        }
 public ActionResult DeleteId(int data)
 {
     using (var dbConn = Helpers.OrmliteConnection.openConn())
         using (var dbTrans = dbConn.OpenTransaction(IsolationLevel.ReadCommitted))
             if (asset.Delete)
             {
                 try
                 {
                     var delete = new DC_Telesales_ManageInfo();
                     delete.ID = data;
                     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" }));
             }
 }