public BaseResponseResult SendUserRegistrationMail(IdentityUserViewModel viewModel) { BaseResponseResult result = new BaseResponseResult(); try { if (string.IsNullOrEmpty(viewModel.Email) == false) { var maiTemplate = new UserRegistrationMail(viewModel.Email, viewModel.InputPassword); //var queueViewModel = maiTemplate.CreateEmailQueueViewModel(viewModel.Email); //var entity = queueViewModel.ToEntityModel<EmailQueue, EmailQueueViewModel>(); //result.IsSucceed = AddEmailIntoQueue(entity); if (result.IsSucceed) { result.Message = AppMessages.Email_Succeed_Message; } else { result.Message = AppMessages.Email_Failed_Message; } } } catch (ApplicationException) { result.IsSucceed = false; result.Message = AppMessages.Email_Failed_Message; } return(result); }
public BaseResponseResult DemandBook(string bookId, string userName) { var response = new BaseResponseResult { IsSucceed = true, Message = AppMessages.RETRIEVED_DETAILS_SUCCESSFULLY }; try { if (!string.IsNullOrWhiteSpace(userName) && ObjectId.Parse(bookId) != default(ObjectId)) { var user = UnitOfWork.UserRepository.FindByUserName(userName); var entityModel = new UserDemandEntityModel { BookId = ObjectId.Parse(bookId), UserId = user.Id, RequestStatus = false, UpdatedBy = user.Id, UpdatedOn = DateTime.Now }; UnitOfWork.UserDemandRepository.Add(entityModel); } else { response.IsSucceed = false; response.Message = AppMessages.INVALID_INPUT; } } catch (Exception ex) { response.IsSucceed = false; response.Message = ex.Message; } return(response); }
public void ProcessRequest(HttpContext context) { BaseResponseResult rc = new BaseResponseResult((int)Code.OperationError, "操作失败!"); try { //获取接口 string action = GetAction(); //操作请求数据 switch (action) { case "joinroom": //将用户ID与ConnectionID关联,并加入到聊天房间中 rc = new JoinRoomHandler().Process(); break; default: rc.SetResult((int)Code.NoAction, "无此接口!"); break; } } catch (Exception ex) { log.Error("直播操作接口出现异常.", ex); rc.SetResult((int)Code.SystemError, "系统错误!"); } rc.Response(); }
/// <summary> /// 返回Json数据 /// </summary> /// <param name="data"></param> /// <returns></returns> protected ActionResult MyJson(BaseResponseResult data) { return(new CustomJsonResult { Data = data, DateTimeFormat = "yyyy-MM-dd HH:mm:ss" }); }
/// <summary> /// timeout request /// </summary> /// <param name="context"></param> /// <returns></returns> private async Task ReturnTimeOut(HttpContext context) { BaseResponseResult response = new BaseResponseResult { Code = "408", Message = "Time Out!" }; context.Response.StatusCode = 408; await context.Response.WriteAsync(JsonConvert.SerializeObject(response)); }
/// <summary> /// not authorized request /// </summary> /// <param name="context"></param> /// <returns></returns> private async Task ReturnNoAuthorized(HttpContext context) { BaseResponseResult response = new BaseResponseResult { Code = "401", Message = "You are not authorized!" }; context.Response.StatusCode = 401; await context.Response.WriteAsync(JsonConvert.SerializeObject(response)); }
protected override BaseResponseResult DoWork(JoinRoomReq param) { BaseResponseResult rc = new BaseResponseResult((int)Code.OperationError, "操作失败!"); if (Index.User != null) { if (param.liveId > 0) { //找到当前直播对应的房间号 LiveChatRoom room = new LiveChatRoomBLL().Find(it => it.LiveID == param.liveId && it.Status == 1); //如果房间存在 if (room != null && room.ID > 0) { //将ConnectionID与UserID绑定到当前直播的房间中 LiveChatRoomMember member = new LiveChatRoomMember { ConnectionID = param.connectionId, RoomID = room.ID, UserID = Index.User.UserID }; member.ID = new LiveChatRoomMemberBLL().Add(member); //如果当前登陆的人员 成功 加入到直播聊天室 if (member.ID > 0) { //这里的代码很重要,这是在外部调用GroupChatHub var context = GlobalHost.ConnectionManager.GetHubContext <GroupChatHub>(); //将当前的ConnectionID加入到 以房间ID为名称的组中 context.Groups.Add(param.connectionId, room.ID.ToString()); //向客户端发送新加入人员信息 context.Clients.Group(room.ID.ToString()).publishMsg(GroupChatHub.FormatMsg("系统消息", Index.User.UserName + " 加入聊天", 0, Index.User.HeadPic)); rc.SetResult(0, "成功加入聊天室!"); } else { rc.SetResult(3, "加入聊天房间失败!"); } } else { rc.SetResult(1, "当前聊天房间不存在!"); } } else { rc.SetResult(1, "当前聊天房间不存在!"); } } else { rc.SetResult(2, "未登录!"); } return(rc); }
public static Mock <IUserDemandService> GetMockService() { GetReadOnlyBookData(); GetReadOnlyUserData(); GetReadOnlyUserDemandData(); var mockService = new Mock <IUserDemandService>(); mockService.Setup(a => a.GetUserDemands(It.IsAny <string>())).Returns <string>(userName => { var response = new ResponseResults <UserDemandDetailViewModel> { IsSucceed = true, ViewModels = new System.Collections.Generic.List <UserDemandDetailViewModel>(), Message = AppMessages.RETRIEVED_DETAILS_SUCCESSFULLY }; if (!string.IsNullOrWhiteSpace(userName)) { var user = userDataCollection.FirstOrDefault(o => o.UserName == userName); var models = userDemandDataCollection.Where(o => o.UserId == user.Id).ToList(); if (models != null && models.Count > 0) { var bookIds = models.Select(o => o.BookId).ToList(); var bookLookUp = bookDataCollection.Where(o => bookIds.Contains(o.Id)).ToDictionary(o => o.Id, o => o.Title); response.ViewModels = models.Select(o => new UserDemandDetailViewModel { BookId = o.BookId, IssuedDate = o.IssuedDate, ReturnedDate = o.ReturnedDate, Remark = o.Remark, UpdatedOn = o.UpdatedOn, UserId = o.UserId, RequestStatus = (o.RequestStatus) ? "Approved" : "Pending", BookTitle = bookLookUp[o.BookId] }).ToList(); } } if (response.ViewModels.Count <= 0) { response.Message = AppMessages.NO_RECORD_FOUND; } return(response); }); mockService.Setup(a => a.DemandBook(It.IsAny <string>(), It.IsAny <string>())).Returns <string, string>((bookId, userName) => { var response = new BaseResponseResult { IsSucceed = true, Message = AppMessages.RETRIEVED_DETAILS_SUCCESSFULLY }; if (!string.IsNullOrWhiteSpace(userName)) { var user = userDataCollection.FirstOrDefault(o => o.UserName == userName); var entityModel = new UserDemandEntityModel { BookId = ObjectId.Parse(bookId), UserId = user.Id, RequestStatus = false, UpdatedBy = user.Id, UpdatedOn = DateTime.Now }; userDemandDataCollection.Add(entityModel); } else { response.IsSucceed = false; response.Message = AppMessages.INVALID_INPUT; } return(response); }); return(mockService); }