public JsonResult GetList() { AjaxMsgResult result = new AjaxMsgResult(); UserPhotoService x_upService = new UserPhotoService(); List <UPInfo> list = new List <UPInfo>(); var upl = x_upService.GetTopList(20); int i = 1; foreach (var item in upl) { UPInfo info = new UPInfo() { I = i, HeadImage = item.HeadImage, NickName = item.NickName, PerValue = item.PerValue }; list.Add(info); i++; } result.Success = true; result.Source = list; result.Code = x_upService.GetMyTop(CurrentUser.ID).ToString(); return(Json(result)); }
public ActionResult xTolist() { UserPhotoService x_upService = new UserPhotoService(); var list = x_upService.GetAllList(); XListInfo xt = new XListInfo(); xt.upList = list; xt.count = list.Count; return(View(xt)); }
public async Task SetUserPhotoAsync_Should_Return_Failure_Result_When_Order_Is_Invalid(int userId, string path, int order) { var userRepositoryMock = new Mock <IUserRepository>(); var mediatorMock = new Mock <IMediator>(); var userPhotoService = new UserPhotoService(userRepositoryMock.Object, mediatorMock.Object); var result = await userPhotoService.SetUserPhotoAsync(userId, path, order); result.IsSuccessed.Should().BeFalse(); result.GetErrorString().Should().Be(UserPhoto.Order_Should_Be_Greater_Than_Zero); }
public async Task SetUserPhotoAsync_Should_Return_Failure_Result_When_User_Id_Is_Invalid(int userId, string path, int order) { var userRepositoryMock = new Mock <IUserRepository>(); var mediatorMock = new Mock <IMediator>(); userRepositoryMock.Setup(x => x.GetUserByIdAsync(userId)).ReturnsAsync(Result.Fail <User>(UserErrorMessages.User_Does_Not_Exist)); var userPhotoService = new UserPhotoService(userRepositoryMock.Object, mediatorMock.Object); var result = await userPhotoService.SetUserPhotoAsync(userId, path, order); result.IsSuccessed.Should().BeFalse(); result.GetErrorString().Should().Be(UserErrorMessages.User_Does_Not_Exist); }
public async Task SetUserPhotoAsync_Should_Return_Success_Result_When_Inputs_Are_Valid(int userId, string path, int order) { var userRepositoryMock = new Mock <IUserRepository>(); var mediatorMock = new Mock <IMediator>(); userRepositoryMock.Setup(x => x.GetUserByIdAsync(userId)).ReturnsAsync(Result.Ok(_user)); userRepositoryMock.Setup(x => x.SaveChangesAsync(It.IsAny <string>())).ReturnsAsync(Result.Ok()); var userPhotoService = new UserPhotoService(userRepositoryMock.Object, mediatorMock.Object); var result = await userPhotoService.SetUserPhotoAsync(userId, path, order); result.IsSuccessed.Should().BeTrue(); }
public static void getPerValue() { string host = ConfigurationManager.AppSettings["host"]; while (true) { UserPhotoService x_upService = new UserPhotoService(); string info = "start --- >> "; var list = x_upService.Get(a => a.PerValue == 0 && a.FatherPhoto != "" && a.ChildPhoto != ""); if (list != null && list.Count > 0) { RequestModel rm = new RequestModel(); foreach (var item in list) { var res = rm.getResult("http://" + host + item.FatherPhoto, "http://" + host + item.ChildPhoto); //info += res.code + ".." + res.Message + "....http://" + host + item.FatherPhoto + "http://" + host + item.ChildPhoto +" "; //Logging4net.WriteInfo(info); if (res != null && res.code == 0) { int similar = Convert.ToInt32(res.data.similarity); if (similar <= 0) { similar = -1; } x_upService.Update(() => new UserPhotoInfo() { PerValue = similar, PerValueTime = DateTime.Now }, a => a.ID == item.ID); } else if (res.code != 0) { x_upService.Update(() => new UserPhotoInfo() { PerValue = -1, PerValueTime = DateTime.Now }, a => a.ID == item.ID); } Thread.Sleep(300); } } else { Thread.Sleep(3000); } } }
public JsonResult getLast() { AjaxMsgResult result = new AjaxMsgResult(); if (!isInTime()) { result.Msg = "活动已过期"; return(Json(result)); } int userid = 0; if (!string.IsNullOrEmpty(Request.Form["uid"])) { userid = Convert.ToInt32(Request.Form["uid"]); } if (userid == 0) { userid = CurrentUser.ID; } UserPhotoService x_upService = new UserPhotoService(); var item = x_upService.GetMyLast(userid); item.FatherPhoto += "_1.jpg"; item.ChildPhoto += "_1.jpg"; if (item != null) { result.Success = true; result.Source = item; } else { result.Success = false; result.Msg = "请先上传照片"; } return(Json(result)); }
public JsonResult upFile() { AjaxMsgResult reuslt = new AjaxMsgResult(); if (!isInTime()) { reuslt.Msg = "活动已过期"; return(Json(reuslt)); } HttpPostedFileBase file = Request.Files[0]; string skey = "x_photo_up"; UpFileTypeInfo uftype = new UpFileTypeInfo(); if (Session[skey] != null) { uftype = Session[skey] as UpFileTypeInfo; } else { Session[skey] = uftype; } if (file != null) { string oripath = "/uploads/" + CurrentUser.ID + "/"; string path = Server.MapPath(oripath); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string filename = DateTime.Now.ToString("yyMMddhhmmssfff") + file.FileName; file.SaveAs(path + filename); ThumbnailHelper.MakeThumbnailImage(path + filename, path + filename + "_1.jpg", 400, 400); string dbpath = oripath + filename; if (string.IsNullOrEmpty(uftype.fatherp)) { uftype.fatherp = dbpath; } else if (string.IsNullOrEmpty(uftype.childp)) { uftype.childp = dbpath; } if (!string.IsNullOrEmpty(uftype.fatherp) && !string.IsNullOrEmpty(uftype.childp)) { UserPhotoService x_upService = new UserPhotoService(); UserPhotoInfo uinfo = new UserPhotoInfo() { UserId = CurrentUser.ID, FatherPhoto = uftype.fatherp, ChildPhoto = uftype.childp, CreateTime = DateTime.Now, IsValid = 1, PerValueTime = DateTime.Now.AddYears(-100) }; x_upService.Insert(uinfo); uftype.fatherp = null; uftype.childp = null; } reuslt.Success = true; reuslt.Source = dbpath + "_1.jpg"; } return(Json(reuslt)); }