public JsonResult Delete([FromBody] int id)
        {
            var mess = new JMessage {
                Error = false, Title = ""
            };

            try
            {
                var data = _context.DispatchesWeekWorkingSchedulerss.FirstOrDefault(x => x.Id == id);
                _context.Remove(data);
                _context.SaveChanges();
                mess.Title = "Xóa sự kiện thành công";
            }
            catch (Exception ex)
            {
                mess.Title = "Xóa sự kiện bị lỗi";
                mess.Error = true;
            }
            return(Json(mess));
        }
Ejemplo n.º 2
0
        public JsonResult Delete(int Id)
        {
            var mess = new JMessage {
                Error = false, Title = ""
            };

            try
            {
                var data = _context.AdAuthorings.FirstOrDefault(x => x.Id == Id);
                _context.Remove(data);
                _context.SaveChanges();
                mess.Title = "Xóa thành công";
            }
            catch (Exception ex)
            {
                mess.Title = "Xóa bị lỗi";
                mess.Error = true;
            }
            return(Json(mess));
        }
Ejemplo n.º 3
0
        public object DeleteItems([FromBody] List <int> listId)
        {
            var msg = new JMessage()
            {
                Error = false
            };

            try
            {
                //_logger.LogInformation(LoggingEvents.LogDb, "Delete list application");
                List <int>           listRef         = new List <int>();
                List <int>           listDel         = new List <int>();
                List <AdApplication> listApplication = new List <AdApplication>();
                foreach (var id in listId)
                {
                    AdApplication obj = _context.AdApplications.FirstOrDefault(x => x.ApplicationId == id);
                    if (obj != null)
                    {
                        var pms     = _context.AdPermissions.FirstOrDefault(x => x.ApplicationCode == obj.ApplicationCode);
                        var appFunc = _context.AdAppFunctions.FirstOrDefault(x => x.ApplicationCode == obj.ApplicationCode);
                        if (appFunc != null || pms != null)
                        {
                            listRef.Add(id);
                        }
                        else
                        {
                            listDel.Add(id);
                        }
                    }
                }
                if (listRef.Count > 0)
                {
                    if (listDel.Count > 0)
                    {
                        foreach (var id in listDel)
                        {
                            AdApplication obj = _context.AdApplications.FirstOrDefault(x => x.ApplicationId == id);
                            listApplication.Add(obj);
                            _context.Remove(obj);
                        }
                        _context.SaveChanges();
                        msg.Error = true;
                        msg.Title = String.Format(CommonUtil.ResourceValue("COM_DEL_SUCCESS_LIST_ITEM_BUT_REF"), CommonUtil.ResourceValue("ADM_APP_LBL_APP").ToLower());
                        //_logger.LogError(LoggingEvents.LogDb, "Delete part of the application list successfully");
                        _actionLog.InsertActionLogDeleteItem("VIB_APPLICATION", "Delete part of the application list successfully", listApplication.ToArray(), null, "Delete");
                    }
                    else
                    {
                        msg.Error = true;
                        msg.Title = String.Format(CommonUtil.ResourceValue("COM_ERR_LIST_OBJ_REF"), CommonUtil.ResourceValue("ADM_APP_LBL_APP").ToLower());
                        //_logger.LogError(LoggingEvents.LogDb, "Delete list application fail");
                        _actionLog.InsertActionLogDeleteItem("VIB_APPLICATION", "Delete list application fail", null, null, "Error");
                    }
                }
                else
                {
                    if (listDel.Count > 0)
                    {
                        foreach (var id in listDel)
                        {
                            AdApplication obj = _context.AdApplications.FirstOrDefault(x => x.ApplicationId == id);
                            listApplication.Add(obj);

                            _context.AdApplications.Attach(obj);
                            _context.AdApplications.Remove(obj);
                        }
                        _context.SaveChanges();
                        msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_DELETE_LIST_SUCCESS"),
                                                  CommonUtil.ResourceValue("ADM_APP_LBL_APP").ToLower());
                        //_logger.LogError(LoggingEvents.LogDb, "Delete part of the application list successfully");
                        _actionLog.InsertActionLogDeleteItem("VIB_APPLICATION", "Delete application list successfully", listApplication.ToArray(), null, "Delete");
                    }
                }
            }
            catch (Exception ex)
            {
                msg.Error  = true;
                msg.Object = ex;
                msg.Title  = String.Format(CommonUtil.ResourceValue("COM_MSG_DELETE_LIST_FAIL"), CommonUtil.ResourceValue("ADM_APP_LBL_APP").ToLower());
                //_logger.LogError(LoggingEvents.LogDb, "Delete list application fail");
                _actionLog.InsertActionLogDeleteItem("VIB_APPLICATION", "Delete list application failed: " + ex.Message, null, null, "Error");
            }
            return(Json(msg));
        }