コード例 #1
0
        public virtual bool Edit(ref ValidationErrors errors, WC_GroupModel model)
        {
            try
            {
                WC_Group entity = m_Rep.GetById(model.Id);
                if (entity == null)
                {
                    errors.Add(Resource.Disable);
                    return(false);
                }
                entity.Id               = model.Id;
                entity.Name             = model.Name;
                entity.Count            = model.Count;
                entity.OfficalAccountId = model.OfficalAccountId;



                if (m_Rep.Edit(entity))
                {
                    return(true);
                }
                else
                {
                    errors.Add(Resource.NoDataChange);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return(false);
            }
        }
コード例 #2
0
        public virtual bool Create(ref ValidationErrors errors, WC_GroupModel model)
        {
            try
            {
                WC_Group entity = m_Rep.GetById(model.Id);
                if (entity != null)
                {
                    errors.Add(Resource.PrimaryRepeat);
                    return(false);
                }
                entity                  = new WC_Group();
                entity.Id               = model.Id;
                entity.Name             = model.Name;
                entity.Count            = model.Count;
                entity.OfficalAccountId = model.OfficalAccountId;


                if (m_Rep.Create(entity))
                {
                    return(true);
                }
                else
                {
                    errors.Add(Resource.InsertFail);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return(false);
            }
        }
コード例 #3
0
        public JsonResult Create(WC_GroupModel model)
        {
            WC_OfficalAccountsModel wcmodel = account_BLL.GetCurrentAccount();

            model.OfficalAccountId = wcmodel.Id;
            model.Id    = System.Guid.NewGuid().ToString();
            model.Count = 0;
            if (model != null && ModelState.IsValid)
            {
                if (m_BLL.Create(ref errors, model))
                {
                    LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",Name" + model.Name, "成功", "添加", "WC_Group");
                    return(Json(JsonHandler.CreateMessage(1, Resource.Create)));
                }
                else
                {
                    string ErrorCol = errors.Error;
                    LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",Name" + model.Name + "," + ErrorCol, "失败", "添加", "WC_Group");
                    return(Json(JsonHandler.CreateMessage(0, Resource.Create + ErrorCol)));
                }
            }
            else
            {
                return(Json(JsonHandler.CreateMessage(0, Resource.Create)));
            }
        }
コード例 #4
0
        public ActionResult Details(string id)
        {
            ViewBag.Perm = GetPermission();
            WC_GroupModel entity = m_BLL.GetById(id);

            return(View(entity));
        }
コード例 #5
0
        public ActionResult Edit(string id)
        {
            ViewBag.Perm = GetPermission();
            WC_GroupModel entity = m_BLL.GetById(id);

            ViewBag.EditUrl = "Edit";
            return(View("Create", entity));
        }
コード例 #6
0
        /// <summary>
        /// 校验Excel数据,这个方法一般用于重写校验逻辑
        /// </summary>
        public virtual bool CheckImportData(string fileName, List <WC_GroupModel> list, ref ValidationErrors errors)
        {
            var targetFile = new FileInfo(fileName);

            if (!targetFile.Exists)
            {
                errors.Add("导入的数据文件不存在");
                return(false);
            }

            var excelFile = new ExcelQueryFactory(fileName);

            //对应列头
            excelFile.AddMapping <WC_GroupModel>(x => x.Name, "Name");
            excelFile.AddMapping <WC_GroupModel>(x => x.Count, "Count");
            excelFile.AddMapping <WC_GroupModel>(x => x.OfficalAccountId, "OfficalAccountId");

            //SheetName
            var excelContent = excelFile.Worksheet <WC_GroupModel>(0);
            int rowIndex     = 1;

            //检查数据正确性
            foreach (var row in excelContent)
            {
                var errorMessage = new StringBuilder();
                var entity       = new WC_GroupModel();
                entity.Id               = row.Id;
                entity.Name             = row.Name;
                entity.Count            = row.Count;
                entity.OfficalAccountId = row.OfficalAccountId;

                //=============================================================================
                if (errorMessage.Length > 0)
                {
                    errors.Add(string.Format(
                                   "第 {0} 列发现错误:{1}{2}",
                                   rowIndex,
                                   errorMessage,
                                   "<br/>"));
                }
                list.Add(entity);
                rowIndex += 1;
            }
            if (errors.Count > 0)
            {
                return(false);
            }
            return(true);
        }
コード例 #7
0
        public virtual WC_GroupModel GetById(object id)
        {
            if (IsExists(id))
            {
                WC_Group      entity = m_Rep.GetById(id);
                WC_GroupModel model  = new WC_GroupModel();
                model.Id               = entity.Id;
                model.Name             = entity.Name;
                model.Count            = entity.Count;
                model.OfficalAccountId = entity.OfficalAccountId;

                return(model);
            }
            else
            {
                return(null);
            }
        }
コード例 #8
0
        public JsonResult GetNetList()
        {
            WC_OfficalAccountsModel model = account_BLL.GetCurrentAccount();
            GroupsJson groupjson          = GroupsApi.Get(model.AccessToken);

            foreach (var item in groupjson.groups)
            {
                WC_GroupModel entity = new WC_GroupModel();
                if (m_BLL.GetById(item.id.ToString()) == null)
                {
                    entity.Id               = item.id.ToString();
                    entity.Name             = item.name;
                    entity.Count            = item.count;
                    entity.OfficalAccountId = model.Id;
                    m_BLL.Create(ref errors, entity);
                }
            }
            return(Json(JsonHandler.CreateMessage(1, "获取成功")));
        }
コード例 #9
0
 public JsonResult Edit(WC_GroupModel model)
 {
     if (model != null && ModelState.IsValid)
     {
         if (m_BLL.Edit(ref errors, model))
         {
             LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",Name" + model.Name, "成功", "修改", "WC_Group");
             return(Json(JsonHandler.CreateMessage(1, Resource.EditSucceed)));
         }
         else
         {
             string ErrorCol = errors.Error;
             LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",Name" + model.Name + "," + ErrorCol, "失败", "修改", "WC_Group");
             return(Json(JsonHandler.CreateMessage(0, Resource.EditFail + ErrorCol)));
         }
     }
     else
     {
         return(Json(JsonHandler.CreateMessage(0, Resource.EditFail)));
     }
 }
コード例 #10
0
        public virtual async Task <Tuple <ValidationErrors, bool> > CreateAsync(WC_GroupModel model)
        {
            ValidationErrors errors = new ValidationErrors();

            try
            {
                WC_Group entity = await m_Rep.GetByIdAsync(model.Id);

                if (entity != null)
                {
                    errors.Add(Resource.PrimaryRepeat);
                    return(new Tuple <ValidationErrors, bool>(errors, false));
                }
                entity                  = new WC_Group();
                entity.Id               = model.Id;
                entity.Name             = model.Name;
                entity.Count            = model.Count;
                entity.OfficalAccountId = model.OfficalAccountId;


                if (await m_Rep.CreateAsync(entity))
                {
                    return(new Tuple <ValidationErrors, bool>(errors, true));
                }
                else
                {
                    errors.Add(Resource.InsertFail);
                    return(new Tuple <ValidationErrors, bool>(errors, false));
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return(new Tuple <ValidationErrors, bool>(errors, false));
            }
        }
コード例 #11
0
        public virtual async Task <Tuple <ValidationErrors, bool> > EditAsync(WC_GroupModel model)
        {
            ValidationErrors errors = new ValidationErrors();

            try
            {
                WC_Group entity = await m_Rep.GetByIdAsync(model.Id);

                if (entity == null)
                {
                    errors.Add(Resource.Disable);
                    return(new Tuple <ValidationErrors, bool>(errors, false));
                }
                entity.Id               = model.Id;
                entity.Name             = model.Name;
                entity.Count            = model.Count;
                entity.OfficalAccountId = model.OfficalAccountId;


                if (await m_Rep.EditAsync(entity))
                {
                    return(new Tuple <ValidationErrors, bool>(errors, true));
                }
                else
                {
                    errors.Add(Resource.NoDataChange);
                    return(new Tuple <ValidationErrors, bool>(errors, false));
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return(new Tuple <ValidationErrors, bool>(errors, false));
            }
        }