/// <summary> /// 移除物品 /// </summary> /// <param name="input">请求信息</param> /// <returns></returns> public async Task <BaseResult <object> > RemoveAsync(RemoveBasketItemDto input) { long pid = input.PId; var store = _redis.GetDatabase(MyShopRedisConfig.BASKETDBNUMBER); var userId = CurrentUser.Id; var key = $"{MyShopRedisConfig.BASKETKEY_PRE}:{userId}"; var basketItem = await store.HashGetAsync(key, pid); if (!basketItem.IsNullOrEmpty) { if (!input.Clear) { long count = await store.HashDecrementAsync(key, pid); if (count <= 0) { await store.HashDeleteAsync(key, pid); } } else { await store.HashDeleteAsync(key, pid); } } return(BaseResult <object> .Success()); }
/// <summary> /// 添加物品 /// </summary> /// <param name="input">请求信息</param> /// <param name="pid">商品id</param> /// <returns></returns> public async Task <BaseResult <object> > AddAsync(AddBasketItemDto input) { long pid = input.PId; var store = _redis.GetDatabase(MyShopRedisConfig.BASKETDBNUMBER); var userId = CurrentUser.Id; var key = $"{MyShopRedisConfig.BASKETKEY_PRE}:{userId}"; var basketItem = await store.HashGetAsync(key, pid); if (!basketItem.IsNullOrEmpty) { await store.HashIncrementAsync(key, pid); } else { var product = await _products.FindAsync(p => p.Id == pid); if (product != null) { if (product.Status != ProductStatus.Normal) { return(BaseResult <object> .Failed("商品已下架!")); } await store.HashIncrementAsync(key, pid); } else { return(BaseResult <object> .Failed("加入购物车失败:商品不见了!")); } } return(BaseResult <object> .Success()); }
public async Task <BaseResult <int> > Handle(CreateYearCourseGroupCommand request, CancellationToken cancellationToken) { var yearCourse = await _unitOfWork.YearCourseRepository.GetAsync(request.YearCourseId); if (yearCourse == null) { return(BaseResult <int> .Fail(ErrorType.NotFound, new List <string> { "Resource not found!" })); } var group = new Group { GroupName = request.GroupName, GroupNumber = request.GroupNumber, YearCourseId = request.YearCourseId }; await _unitOfWork.GroupRepository.AddAsync(group); await _unitOfWork.CommitAsync(); return(BaseResult <int> .Success(ResultType.Created, group.Id)); }
public virtual async Task <IResult> SaveChangesAsync(CancellationToken cancellationToken = default) { TError baseError = new TError { Code = "updata", Description = "保存失败" }; IResult result = new IResult(); try { if (AutoSaveChanges) { var row = await Context.SaveChangesAsync(cancellationToken); if (row > 0) { result = BaseResult <IResult, TError> .Success(row); } } } catch (DbUpdateConcurrencyException ex) { baseError.Code = ex.Source; baseError.Description = ex.Message; result = BaseResult <IResult, TError> .Failed(baseError); Logger.Log(LogLevel.Error, ex, "error", result); } return(result); }
public async Task <BaseResult <int> > Handle(CreateYearCourseSubjectCommand request, CancellationToken cancellationToken) { var yearCourse = await _unitOfWork.YearCourseRepository.GetAsync(request.YearCourseId); if (yearCourse == null) { return(BaseResult <int> .Fail(ErrorType.NotFound, new List <string> { "Resource not found!" })); } var subject = new Subject { Name = request.Name, ShortName = request.ShortName, YearCourseId = request.YearCourseId }; await _unitOfWork.SubjectRepository.AddAsync(subject); await _unitOfWork.CommitAsync(); return(BaseResult <int> .Success(ResultType.Created, subject.Id)); }
public static BaseResult PrintTxt(string data, string printType) { try { Setting setting = FileUtils.GetSetting(); if (string.IsNullOrEmpty(setting.Name)) { return(BaseResult.Error("请先设置默认打印机")); } if (string.IsNullOrEmpty(data)) { return(BaseResult.Error("要打印的数据不存在")); } streamToPrint = printType == "FILEPATH" ? new StreamReader(data) : new StreamReader(data); try { printFont = new Font("Arial", 10); PrintDocument pd = new PrintDocument(); pd.PrintPage += new PrintPageEventHandler (PdPrintPage); pd.Print(); } finally { streamToPrint.Close(); } } catch (Exception e) { return(BaseResult.Error(e.Message)); } return(BaseResult.Success("")); }
public async Task <BaseResult <ProductDetailsDto> > GetAsync(long id) { var query = Query(p => p.Id == id).FirstOrDefault(); if (query != null) { var details = Task.Run(() => { var result = ObjectMapper.Map <ProductItemDto, ProductDetailsDto>(query); var attachments = _productAttachmentRepository.Where(p => p.ProductId == query.Id).ToList(); if (attachments.Any()) { result.Images = attachments.Where(p => p.Type == ProductAttachmentType.Image).Select(x => x.Content).ToList(); result.Summary = attachments.FirstOrDefault(p => p.Type == ProductAttachmentType.Summary)?.Content; } else { result.Images = new List <string>() { query.CoverImage }; } return(result); }); return(BaseResult <ProductDetailsDto> .Success(await details)); } return(BaseResult <ProductDetailsDto> .Error("获取商品信息失败!")); }
public async Task <BaseResult <Event> > Handle(GetEventDetailsQuery request, CancellationToken cancellationToken) { //Check if year course exists & if request.eventId belongs to this yearCourse var yearCourse = await _unitOfWork.YearCourseRepository.GetAsync(request.YearCourseId); var eventToFetch = await _unitOfWork.EventRepository.GetAsync(request.EventId); if (eventToFetch == null || yearCourse == null) { return(BaseResult <Event> .Fail(ErrorType.NotFound, new List <string> { "Resource not found!" })); } if (!yearCourse.Events.Any(x => x.Id == request.EventId)) { return(BaseResult <Event> .Fail(ErrorType.NotFound, new List <string> { "Requested event doesnt belong to given YearCourse!" })); } return(BaseResult <Event> .Success(ResultType.Ok, eventToFetch)); }
/// <summary> /// 登录 /// </summary> /// <param name="loginInfo">登录信息</param> /// <returns></returns> public async Task <BaseResult <TokenInfo> > Login(UserLoginDto loginInfo) { if (string.IsNullOrEmpty(loginInfo.Account) || string.IsNullOrEmpty(loginInfo.Password)) { return(BaseResult <TokenInfo> .Failed("用户名密码不能为空!")); } var user = await Task.FromResult(_userRepository.FirstOrDefault(p => p.Account == loginInfo.Account)); if (user == null) { return(BaseResult <TokenInfo> .Failed("用户名密码错误!")); } string md5Pwd = EncryptHelper.MD5Encrypt(loginInfo.Password); if (user.Password != md5Pwd) { return(BaseResult <TokenInfo> .Failed("用户名密码错误!")); } var claims = GetClaims(user); var token = GenerateToken(claims); return(BaseResult <TokenInfo> .Success(token)); }
/// <summary> /// 清空购物车 /// </summary> /// <returns></returns> public async Task <BaseResult <object> > ClearAsync() { var store = _redis.GetDatabase(MyShopRedisConfig.BASKETDBNUMBER); var userId = CurrentUser.Id; var key = $"{MyShopRedisConfig.BASKETKEY_PRE}:{userId}"; await store.KeyDeleteAsync(key); return(BaseResult <object> .Success()); }
/// <summary> /// 修改物品数量 /// </summary> /// <param name="input">请求信息</param> /// <returns></returns> public async Task <BaseResult <object> > ChangeAsync(ChangeBasketItemDto input) { long pid = input.PId; var store = _redis.GetDatabase(MyShopRedisConfig.BASKETDBNUMBER); var userId = CurrentUser.Id; var key = $"{MyShopRedisConfig.BASKETKEY_PRE}:{userId}"; await store.HashSetAsync(key, new HashEntry[] { new HashEntry(pid, input.Count) }); return(BaseResult <object> .Success()); }
/// <summary> /// 注册 /// </summary> /// <param name="registerInfo">注册信息</param> /// <param name="cancellationToken">取消令牌</param> /// <returns></returns> public async Task <BaseResult <TokenInfo> > Register(UserRegisterDto registerInfo, CancellationToken cancellationToken) { var user = ObjectMapper.Map <UserRegisterDto, User>(registerInfo); var registeredUser = await _userRepository.InsertAsync(user, true, cancellationToken); var claims = GetClaims(user); var token = GenerateToken(claims); return(BaseResult <TokenInfo> .Success(token)); }
public async Task <BaseResult <YearCourse> > Handle(GetYearCourseByIdQuery request, CancellationToken cancellationToken) { var yearCourse = await _unitOfWork.YearCourseRepository.GetAsync(request.YearCourseId); if (yearCourse == null) { return(BaseResult <YearCourse> .Fail(ErrorType.NotFound, new List <string> { "Resource not found!" })); } return(BaseResult <YearCourse> .Success(ResultType.Ok, yearCourse)); }
public async Task <BaseResult <List <Group> > > Handle(GetAllYearCourseGroupsQuery request, CancellationToken cancellationToken) { var yearCourse = await _unitOfWork.YearCourseRepository.GetAsync(request.YearCourseId); if (yearCourse == null) { return(BaseResult <List <Group> > .Fail(ErrorType.NotFound, new List <string> { "Year course not found!" })); } var groups = await _unitOfWork.GroupRepository.GetAllForYearCourseAsync(request.YearCourseId); return(BaseResult <List <Group> > .Success(ResultType.Ok, groups)); }
public async Task <BaseResult <List <Event> > > Handle(GetYearCourseEventsQuery request, CancellationToken cancellationToken) { var yearCourse = await _unitOfWork.YearCourseRepository.GetAsync(request.YearCourseId); if (yearCourse == null) { return(BaseResult <List <Event> > .Fail(ErrorType.NotFound, new List <string> { "Year course does not exist!" })); } var events = await _unitOfWork.EventRepository.GetYearCourseEventAsync(request.YearCourseId, request.Date, request.GroupIds); return(BaseResult <List <Event> > .Success(ResultType.Ok, events)); }
public async Task <BaseResult <int> > Handle(CreateYearCourseCommand request, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(request.CreationApiKey)) { return(BaseResult <int> .Fail(ErrorType.NotAuthenticated, new List <string> { "No password provided!" })); } if (await _unitOfWork.KeyRepository.TryUseKeyAsync(request.CreationApiKey)) { var yearCourse = new YearCourse { Password = request.Password, CurrentSemester = request.CurrentSemester, Course = request.Course, CourseStartYear = request.CourseStartYear, Faculty = request.Faculty, University = request.University, Groups = request.Groups.Select(g => new Group { GroupName = g.GroupName, GroupNumber = g.GroupNumber }).ToList(), Subjects = request.Subjects.Select(s => new Subject { Name = s.Name, ShortName = s.ShortName }).ToList() }; await _unitOfWork.YearCourseRepository.AddAsync(yearCourse); await _unitOfWork.CommitAsync(); return(BaseResult <int> .Success(ResultType.Created, yearCourse.Id)); } await _unitOfWork.RollbackAsync(); return(BaseResult <int> .Fail(ErrorType.NotAuthorized, new List <string> { "Invalid creation api key!" })); }
public async Task <BaseResult <int> > Handle(CreateEventCommand request, CancellationToken cancellationToken) { var yearCourse = await _unitOfWork.YearCourseRepository.GetAsync(request.YearCourseId); if (yearCourse == null) { return(BaseResult <int> .Fail(ErrorType.NotFound, new List <string> { "Resource not found!" })); } var eventToAdd = new Event { Name = request.Name, Description = request.Description, YearCourseId = request.YearCourseId, Date = request.Date, EventTypeId = request.EventTypeId, SubjectId = request.SubjectId, GroupEvents = new List <GroupEvent>() }; await _unitOfWork.EventRepository.AddAsync(eventToAdd); request.GroupIds.ForEach(x => { eventToAdd.GroupEvents.Add(new GroupEvent { EventId = eventToAdd.Id, GroupId = x }); }); await _unitOfWork.CommitAsync(); return(BaseResult <int> .Success(ResultType.Created, eventToAdd.Id)); }
public async Task <BaseResult <int> > Handle(CreateEventTypeCommand request, CancellationToken cancellationToken) { var yearCourse = await _unitOfWork.YearCourseRepository.GetAsync(request.YearCourseId); if (yearCourse == null) { return(BaseResult <int> .Fail(ErrorType.NotFound, new List <string> { "Year course not found!" })); } var eventType = new EventType() { Name = request.Name }; await _unitOfWork.EventTypeRepository.AddAsync(eventType); await _unitOfWork.CommitAsync(); return(BaseResult <int> .Success(ResultType.Created, eventType.Id)); }
public async Task <BaseResult <Subject> > Handle(GetYearCourseSubjectByIdQuery request, CancellationToken cancellationToken) { var yearCourse = await _unitOfWork.YearCourseRepository.GetAsync(request.YearCourseId); if (yearCourse == null) { return(BaseResult <Subject> .Fail(ErrorType.NotFound, new List <string> { "Year course not found!" })); } var subject = await _unitOfWork.SubjectRepository.GetYearCourseSubject(request.YearCourseId, request.SubjectId); if (subject == null) { return(BaseResult <Subject> .Fail(ErrorType.NotFound, new List <string> { "Subject not found!" })); } return(BaseResult <Subject> .Success(ResultType.Ok, subject)); }
public async Task <BaseResult <List <Event> > > Handle(GetYearCourseEventsForGroupQuery request, CancellationToken cancellationToken) { var yearCourse = await _unitOfWork.YearCourseRepository.GetAsyncWithGroups(request.YearCourseId); if (yearCourse == null) { return(BaseResult <List <Event> > .Fail(ErrorType.NotFound, new List <string> { "Year course does not exist!" })); } if (!yearCourse.Groups.Any(x => x.Id == request.GroupId)) { return(BaseResult <List <Event> > .Fail(ErrorType.NotFound, new List <string> { "Given group does not exist or does not belong to given year course!" })); } var events = await _unitOfWork.EventRepository.GetYearCourseEventsForGroupAsync(request.YearCourseId, request.GroupId, request.Date); return(BaseResult <List <Event> > .Success(ResultType.Ok, events)); }
public BaseResult SetContactWay(int userId, int contactorID, List<ContactWay> cWay, int compId, string confParticipatePhoneNo) { var rs = new BaseResult { State = false, Value = -1, Desc = "数据操作层初始化" }; if (userId <= 0) { rs.Failed(-101, "userId无效"); return rs; } if (contactorID <= 0) { rs.Failed(-102, "contactorID无效"); return rs; } if (cWay.Equals(null)) { rs.Failed(-103, "cWay无效"); return rs; } _desc = "某个终端客户设置(修改)某个联系人的某个联系方式"; _procName = "UP_Addr_Contactor_AddMutilField"; _methodName = MethodBase.GetCurrentMethod().Name; _log = new LogBuilder { Method = string.Format("类[{0}]方法[{1}]", ClassName, _methodName), Desc = _desc, Database = _databaseName, StroreProcedure = _procName }; _log.Append("userId", userId); _log.Append("contactorID", contactorID); _log.Append("ContactWay", cWay); try { XMLContactWayClass wayClass = new XMLContactWayClass(); XmlContactWay xmlWay = null; List<XmlContactWay> list = new List<XmlContactWay>(); foreach (ContactWay way in cWay) { xmlWay = new XmlContactWay(); xmlWay.ContactWayType = way.ContactWayType; xmlWay.Way = way.Way; list.Add(xmlWay); } wayClass.XmlContactWay = list.ToArray(); string wayData = XmlHelper.XmlSerializer<XMLContactWayClass>(wayClass); wayData = wayData.Replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>", ""); var parameters = new[] { _addrDatabase.MakeInParam("@userId", SqlDbType.Int, 4, userId), _addrDatabase.MakeInParam("@CompID", SqlDbType.Int, 4, compId), _addrDatabase.MakeInParam("@ContactorID", SqlDbType.BigInt, 4, contactorID), _addrDatabase.MakeInParam("@ContactWay", SqlDbType.Xml, int.MaxValue, wayData), _addrDatabase.MakeInParam("@ConfParticipatePhoneNo",SqlDbType.VarChar,50,confParticipatePhoneNo ) }; _addrDatabase.ExecuteProc(_procName, parameters, out _result); if (_result != 0) { rs.Failed(-2, "todo"); return rs; } } catch (Exception ex) { rs.Failed(-1, ex.ToString()); _log.Exception = string.Format("{0},发生异常:{1}", _desc, ex.Message); _log.Error(); return rs; } finally { _addrDatabase.Close();//仅显式关闭链接,不做其它操作 } rs.Success(); return rs; }
public BaseResult SendSms(SmsInfo sms) { var rs = new BaseResult { State = false, Value = -1, Desc = "数据操作层初始化" }; if (sms.UserID <= 0) { rs.Failed(-101, "userId无效"); return rs; } if (sms == null) { rs.Failed(-102, "sms无效"); return rs; } _desc = "发送短信"; _procName = "UP_SMS_AddSms"; _methodName = MethodBase.GetCurrentMethod().Name; _log = new LogBuilder { Method = string.Format("类[{0}]方法[{1}]", ClassName, _methodName), Desc = _desc, Database = _databaseName, StroreProcedure = _procName }; _log.Append("userId", sms.UserID); try { StringBuilder smsDetailXML = new StringBuilder(); smsDetailXML.Append("<SmsList>"); sms.SmsDetailList.ForEach((item) => { smsDetailXML.Append("<Sms>"); smsDetailXML.AppendFormat("<Mobile>{0}</Mobile>", item.Mobile); smsDetailXML.AppendFormat("<Name>{0}</Name>", item.Name); smsDetailXML.Append("</Sms>"); }); smsDetailXML.Append("</SmsList>"); var parameters = new[] { _smsDatabase.MakeInParam("@UserId", SqlDbType.Int, 4, sms.UserID), _smsDatabase.MakeInParam("@TaskName", SqlDbType.VarChar, sms.TaskName), _smsDatabase.MakeInParam("@Sender", SqlDbType.VarChar, sms.Sender), _smsDatabase.MakeInParam("@Priority", SqlDbType.Int,(int) sms.Priority), _smsDatabase.MakeInParam("@InputType", SqlDbType.Int,(int) sms.InputType), _smsDatabase.MakeInParam("@SendWay", SqlDbType.Int, (int)sms.SendWay), _smsDatabase.MakeInParam("@SendTime", SqlDbType.DateTime, sms.SendTime), _smsDatabase.MakeInParam("@SubmitTime", SqlDbType.DateTime, sms.SubmitTime), _smsDatabase.MakeInParam("@Message", SqlDbType.VarChar, sms.Message), _smsDatabase.MakeInParam("@SmsType", SqlDbType.VarChar, (int)sms.SmsType), _smsDatabase.MakeInParam("@SmsDetailXML",SqlDbType.Xml,smsDetailXML.ToString()), _smsDatabase.MakeOutParam("@MsgID", SqlDbType.VarChar,16) }; _smsDatabase.ExecuteProc(_procName, parameters, out _result); if (_result != 1) { rs.Failed(-2, "todo"); return rs; } } catch (Exception ex) { rs.Failed(-1, "todo"); _log.Exception = string.Format("{0},发生异常:{1}", _desc, ex.Message); _log.Error(); return rs; } finally { _smsDatabase.Close();//仅显式关闭链接,不做其它操作 } rs.Success(); return rs; }
public BaseResult SetName(int userId, int contactorID, string name, int compId) { var rs = new BaseResult { State = false, Value = -1, Desc = "数据操作层初始化" }; if (userId <= 0) { rs.Failed(-101, "userId无效"); return rs; } if (contactorID <= 0) { rs.Failed(-102, "contactorID无效"); return rs; } if (string.IsNullOrEmpty(name)) { rs.Failed(-103, "name无效"); return rs; } _desc = "某个终端客户修改某个联系人的姓名"; _procName = "UP_Addr_Contactor_SetName"; _methodName = MethodBase.GetCurrentMethod().Name; _log = new LogBuilder { Method = string.Format("类[{0}]方法[{1}]", ClassName, _methodName), Desc = _desc, Database = _databaseName, StroreProcedure = _procName }; _log.Append("userId", userId); _log.Append("contactorID", contactorID); _log.Append("name", name); try { SqlParameter[] parameters = { _addrDatabase.MakeInParam("@ContactorID", SqlDbType.BigInt, 4, contactorID), _addrDatabase.MakeInParam("@ContactorName", SqlDbType.NVarChar, 20, name) }; _addrDatabase.ExecuteProc(_procName, parameters, out _result); if (_result != 0) { rs.Failed(-2, "todo"); return rs; } } catch (Exception ex) { rs.Failed(-1, "todo"); _log.Exception = string.Format("{0},发生异常:{1}", _desc, ex.Message); _log.Error(); return rs; } finally { _addrDatabase.Close();//仅显式关闭链接,不做其它操作 } rs.Success(); return rs; }
public BaseResult AddContactor(int userId, Contactor contactor, int compId) { var rs = new BaseResult { State = false, Value = -1, Desc = "数据操作层初始化" }; if (userId <= 0) { rs.Failed(-101, "userId无效"); return rs; } if (contactor.Equals(null)) { rs.Failed(-101, "contactor无效"); return rs; } _desc = "某个终端客户添加一个联系人,含分组,联系方式"; _procName = "UP_Addr_Contactor_AddContactor"; _methodName = MethodBase.GetCurrentMethod().Name; _log = new LogBuilder { Method = string.Format("类[{0}]方法[{1}]", ClassName, _methodName), Desc = _desc, Database = _databaseName, StroreProcedure = _procName }; _log.Append("userId", userId); try { //联系方式xml var wayClass = new XMLContactWayClass { XmlContactWay = contactor.CWays.Select( way => new XmlContactWay { ContactWayType = way.ContactWayType, Way = way.Way }).ToArray() }; var wayData = XmlHelper.XmlSerializer<XMLContactWayClass>(wayClass); wayData = wayData.Replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>", ""); //分组xml var groupClass = new XMLContactGroupClass { XmlContactGroup = contactor.CGroups.Select( @group => new XmlContactGroup { ContactorGroupID = @group.ContactorGroupID }).ToArray() }; var groupData = XmlHelper.XmlSerializer<XMLContactGroupClass>(groupClass); groupData = groupData.Replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>", ""); var parameters = new[] { _addrDatabase.MakeInParam("@userId", SqlDbType.Int, 4, userId), _addrDatabase.MakeInParam("@CompID", SqlDbType.Int, 4, compId), _addrDatabase.MakeInParam("@Name", SqlDbType.VarChar, 20, contactor.ContactorName), _addrDatabase.MakeInParam("@ContactWay", SqlDbType.Xml, int.MaxValue, wayData), _addrDatabase.MakeInParam("@ContactGroup", SqlDbType.Xml, int.MaxValue, groupData), _addrDatabase.MakeInParam("@ConfParticipatePhoneNo",SqlDbType.VarChar,50,contactor.ConfParticipatePhoneNo) }; _addrDatabase.ExecuteProc(_procName, parameters, out _result); if (_result != 0) { rs.Failed(-2, "todo"); return rs; } } catch (Exception ex) { rs.Failed(-1, ex.ToString()); _log.Exception = string.Format("{0},发生异常:{1}", _desc, ex.Message); _log.Error(); return rs; } finally { _addrDatabase.Close();//仅显式关闭链接,不做其它操作 } rs.Success(); return rs; }
/// <summary> /// 获取订单信息 /// </summary> /// <param name="id">订单id</param> /// <returns></returns> public async Task <BaseResult <OrderInfoDto> > GetAsync(long id) { var order = await _orderRepository.GetAsync(g => g.Id == id); return(BaseResult <OrderInfoDto> .Success(ObjectMapper.Map <Order, OrderInfoDto>(order))); }
public BaseResult SetContactorGroups(int userId, List<ContactorGroup> groups, int contactorID, int compId) { var rs = new BaseResult { State = false, Value = -1, Desc = "数据操作层初始化" }; if (userId <= 0) { rs.Failed(-101, "userId无效"); return rs; } if (groups.Equals(null)) { rs.Failed(-102, "groups无效"); return rs; } if (contactorID <= 0) { rs.Failed(-102, "contactorID无效"); return rs; } _desc = "更新单个联系人与多个联系组之间的所属关系(加入到组或从组中退出)"; _procName = "UP_Addr_Contactor_AddSingleToCGroups"; _methodName = MethodBase.GetCurrentMethod().Name; _log = new LogBuilder { Method = string.Format("类[{0}]方法[{1}]", ClassName, _methodName), Desc = _desc, Database = _databaseName, StroreProcedure = _procName }; _log.Append("userId", userId); _log.Append(" List<MODEL.Addr.ContactorGroup>", groups); _log.Append("contactorID", contactorID); try { //分组xml var groupClass = new XMLContactGroupClass { XmlContactGroup = groups.Select( @group => new XmlContactGroup { ContactorGroupID = @group.ContactorGroupID }).ToArray() }; var groupData = XmlHelper.XmlSerializer<XMLContactGroupClass>(groupClass); groupData = groupData.Replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>", ""); var parameters = new[] { _addrDatabase.MakeInParam("@userId", SqlDbType.Int, 4, userId), _addrDatabase.MakeInParam("@CompID", SqlDbType.Int, 4, compId), _addrDatabase.MakeInParam("@ContactorID", SqlDbType.Int, 4, contactorID), _addrDatabase.MakeInParam("@ContactorGroupIDList", SqlDbType.Xml, int.MaxValue, groupData) }; _addrDatabase.ExecuteProc(_procName, parameters, out _result); if (_result != 0) { rs.Failed(-2, "todo"); return rs; } } catch (Exception ex) { rs.Failed(-1, ex.ToString()); _log.Exception = string.Format("{0},发生异常:{1}", _desc, ex.Message); _log.Error(); return rs; } finally { _addrDatabase.Close();//仅显式关闭链接,不做其它操作 } rs.Success(); return rs; }
public async Task <BaseResult <List <EventType> > > Handle(GetAllEventTypesQuery request, CancellationToken cancellationToken) { var eventTypes = await _unitOfWork.EventTypeRepository.GetAllAsync(); return(BaseResult <List <EventType> > .Success(ResultType.Ok, eventTypes)); }
public BaseResult DelContactorsByGroup(int userId, List<Contactor> contactors, int compId, int groupId) { var rs = new BaseResult { State = false, Value = -1, Desc = "数据操作层初始化" }; if (userId <= 0) { rs.Failed(-101, "userId无效"); return rs; } if (contactors == null) { rs.Failed(-102, "contactors无效"); return rs; } if (groupId <= 0) { rs.Failed(-103, "groupId无效"); return rs; } _desc = "某个终端客户删除某些联系人,从联系人分组中删除,批量操作"; _procName = "UP_Addr_Contactor_DelFromSingleCGroup"; _methodName = MethodBase.GetCurrentMethod().Name; _log = new LogBuilder { Method = string.Format("类[{0}]方法[{1}]", ClassName, _methodName), Desc = _desc, Database = _databaseName, StroreProcedure = _procName }; _log.Append("userId", userId); try { var contactorIDList = contactors.Aggregate("", (current, contactorsId) => current + (contactorsId.ContactorID + ",")); contactorIDList = contactorIDList.Substring(0, contactorIDList.Length - 1); var parameters = new[] { _addrDatabase.MakeInParam("@userId", SqlDbType.Int, 4, userId), _addrDatabase.MakeInParam("@ContactorIDList", SqlDbType.VarChar, 256, contactorIDList), _addrDatabase.MakeInParam("@ContactGroupID", SqlDbType.Int,4,groupId) }; _addrDatabase.ExecuteProc(_procName, parameters, out _result); if (_result != 1) { rs.Failed(-2, "todo"); return rs; } } catch (Exception ex) { rs.Failed(-1, ex.ToString()); _log.Exception = string.Format("{0},发生异常:{1}", _desc, ex.Message); _log.Error(); return rs; } finally { _addrDatabase.Close();//仅显式关闭链接,不做其它操作 } rs.Success(); return rs; }