コード例 #1
0
        public async Task <TableDataModel> LoadDataAsync(ManagerRequestModel model)
        {
            string conditions = "where IsDelete=0 ";//未删除的

            if (!model.Key.IsNullOrWhiteSpace())
            {
                conditions += $"and (UserName like '%@Key%' or NickName like '%@Key%' or Remark like '%@Key%' or Mobile like '%@Key%' or Email like '%@Key%')";
            }
            var data = await _repository.GetListPagedAsync(model.Page, model.Limit, conditions, "id desc", model);

            var list     = data.ToList();
            var viewList = new List <ManagerListModel>();

            list?.ForEach(x =>
            {
                var item      = _mapper.Map <ManagerListModel>(x);
                item.RoleName = _roleRepository.GetNameById(x.RoleId);
                viewList.Add(item);
            });
            return(new TableDataModel
            {
                count = await _repository.RecordCountAsync(conditions),
                data = viewList,
            });
        }
コード例 #2
0
ファイル: ManagerServices.cs プロジェクト: granhal/fxs
        public async Task <string> AddOne(ManagerRequestModel managerRequestModel)
        {
            try
            {
                managerRequestModel._id      = ObjectId.GenerateNewId();
                managerRequestModel.Created  = DateTime.UtcNow;
                managerRequestModel.Modified = DateTime.UtcNow;
                managerRequestModel.Uid      = GenerateIdUtils.GenerateId();
                await _mongoCollection.InsertOneAsync(managerRequestModel);

                return(managerRequestModel.Uid);
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #3
0
ファイル: ManagerController.cs プロジェクト: granhal/fxs
 public async Task <IActionResult> UpdateAsync(int id, ManagerRequestModel managerRequestModel)
 {
     try
     {
         return(Ok(await _services.UpdateOne(id, managerRequestModel)));
     }
     catch (FXSException fxse)
     {
         return(StatusCode(Int32.Parse(fxse.Code), new ExceptionModel {
             Message = fxse.Message, Code = fxse.Code
         }));
     }
     catch (Exception ex)
     {
         return(NotFound(ex.Message));
     }
 }
コード例 #4
0
ファイル: ManagerController.cs プロジェクト: granhal/fxs
 public async Task <IActionResult> AddOneAsync(ManagerRequestModel managerRequestModel)
 {
     try
     {
         if (ModelState.IsValid)
         {
             return(Ok(await _services.AddOne(managerRequestModel)));
         }
         throw new FXSException("Model is invalid", "401");
     }
     catch (FXSException fxse)
     {
         return(StatusCode(Int32.Parse(fxse.Code), new ExceptionModel {
             Message = fxse.Message, Code = fxse.Code
         }));
     }
     catch (Exception ex)
     {
         return(NotFound(ex.Message));
     }
 }
コード例 #5
0
        public TableDataModel LoadData(ManagerRequestModel model)
        {
            string conditions = "where IsDelete=0 ";

            if (!model.Key.IsNullOrWhiteSpace())
            {
                conditions += $" and (username like '%@Key%' or NickName like '%@Key%' or Remark like '%@Key%' or Mobile like '%@Key%' or Email like '%@Key%')";
            }
            var list     = _repository.GetListPaged(model.Page, model.Limit, conditions, " Id desc", model).ToList();
            var viewList = new List <ManagerListModel>();

            list.ForEach(x =>
            {
                var item      = _mapper.Map <ManagerListModel>(x);
                item.RoleName = _roleRepository.GetNameById(x.ROLEID);
                viewList.Add(item);
            });
            return(new TableDataModel
            {
                count = _repository.RecordCount(conditions),
                data = viewList
            });
        }
コード例 #6
0
ファイル: ManagerServices.cs プロジェクト: granhal/fxs
        public async Task <object> UpdateOne(int id, ManagerRequestModel managerRequestModel)
        {
            try
            {
                var update = Builders <ManagerRequestModel> .Update.Set("created", DateTime.UtcNow);

                foreach (BsonElement item in managerRequestModel.ToBsonDocument())
                {
                    if (item.Name != "modified" && item.Name != "created" && item.Name != "_id" && item.Value.GetType() != typeof(BsonNull))
                    {
                        update = update.Set(item.Name, item.Value);
                    }
                }
                update = update.Set("modified", DateTime.UtcNow);
                await _mongoCollection.UpdateOneAsync(Builders <ManagerRequestModel> .Filter.Eq("uid", id.ToString()), update);

                return(string.Format("{0} update success", id));
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #7
0
 public string LoadData([FromQuery] ManagerRequestModel model)
 {
     return(JsonHelper.ObjectToJSON(_service.LoadData(model)));
 }
コード例 #8
0
 public async Task <string> LoadData([FromQuery] ManagerRequestModel model)
 {
     return(JsonHelper.ObjectToJSON(await _service.LoadDataAsync(model)));
 }
コード例 #9
0
        /// <summary>
        /// 加载列表数据
        /// </summary>
        /// <param name="requestModel"></param>
        /// <returns></returns>
        public IActionResult LoadData([FromQuery] ManagerRequestModel requestModel)
        {
            var table = new TableDataModel();

            return(Json(table));
        }