public HttpResponseMessage CancelFollow(long FollowingId, long FollowedId) { FollowRecord followRecord = db.FollowRecords.FirstOrDefault(s => s.FollowingId == FollowingId && s.FollowedId == FollowedId); if (followRecord == null) { return(ApiResponse.BadRequest("您已取消关注")); } User followedUser = db.Users.FirstOrDefault(s => s.Id == FollowedId); User followingUser = db.Users.FirstOrDefault(s => s.Id == FollowingId); try { followedUser.FansNumber -= 1; followingUser.FollowNumber -= 1; db.Entry(followedUser).State = EntityState.Modified; db.Entry(followingUser).State = EntityState.Modified; db.FollowRecords.Remove(followRecord); db.SaveChanges(); } catch (Exception ex) { db.Entry(followedUser).State = EntityState.Unchanged; db.Entry(followingUser).State = EntityState.Unchanged; return(ApiResponse.BadRequest("取消关注失败")); } return(ApiResponse.Ok("取消关注成功")); }
public IActionResult AddFollowRecord([Bind("FollowRecordId, FollowUserId, UserId")] FollowRecord followRecord) { var TopicId = followRecord.FollowRecordId; followRecord.FollowRecordId = null; if (ModelState.IsValid) { followRecord.AddTime = DateTime.Now; _followRecord.Add(followRecord); } return(RedirectToAction("Index", "Topic", new { Id = TopicId })); }
public IActionResult CancelFollowRecord([Bind("FollowRecordId,UserId,,FollowUserId,AddTime")] FollowRecord followRecord) { if (!_signInManager.IsSignedIn(User)) { return(RedirectToAction("Login")); } var followRecordBak = _followRecord.GetById(followRecord.FollowRecordId); followRecordBak.User = null; followRecordBak.FollowUser = null; _followRecord.Delete(followRecordBak); return(RedirectToAction("FollowRecord")); }
public HttpResponseMessage AddFollow(long FollowingId, long FollowedId) { FollowRecord checkRecord = db.FollowRecords.FirstOrDefault(s => s.FollowedId == FollowedId && s.FollowingId == FollowingId); if (checkRecord != null) { return(ApiResponse.BadRequest("您已关注过此用户")); } if (FollowedId == FollowingId) { return(ApiResponse.BadRequest("自己不能关注自己")); } FollowRecord followRecord = new FollowRecord { FollowedId = FollowedId, FollowingId = FollowingId, FollowTime = DateTime.Now }; User followedUser = db.Users.FirstOrDefault(s => s.Id == FollowedId); followedUser.FansNumber += 1; User followingUser = db.Users.FirstOrDefault(s => s.Id == FollowingId); followingUser.FollowNumber += 1; try { db.FollowRecords.Add(followRecord); db.Entry(followedUser).State = EntityState.Modified; db.Entry(followingUser).State = EntityState.Modified; db.SaveChanges(); } catch (Exception ex) { return(ApiResponse.BadRequest(ex.Message)); } return(ApiResponse.Ok(new { followRecord.FollowTime, Message = "用户 " + followingUser.Username + " 关注用户 " + followedUser.Username + " 成功!" })); }
/// <summary> /// 新增跟进记录 /// </summary> /// <param name="obj"></param> /// <returns></returns> public static bool AddFollow(FollowRecord obj) { bool ret = false; try { MsSqlMapperHepler.Insert <FollowRecord>(obj, DBKeys.PRX); Appointment ap = GetOneByID(obj.APID); if (ap.ApStateID == 1)//如果之前是未跟进则改成已跟进 { ap.ApStateID = 2; } MsSqlMapperHepler.Update <Appointment>(ap, DBKeys.PRX); ret = true; } catch (Exception ex) { throw new Exception(ex.Message); } return(ret); }
/// <summary> /// 新增跟进记录 /// </summary> /// <returns></returns> public JsonResult AddFollow() { AjaxStatusModel ajax = new AjaxStatusModel(); //功能操作类的返回类型都是AjaxStatusModel,数据放到AjaxStatusModel.data中,前台获取json后加载 ajax.status = EnumAjaxStatus.Error; //默认失败 ajax.msg = "跟进失败!"; //前台获取,用于显示提示信息 var data = Request["data"]; //获取前台传递的数据,主要序列化 if (string.IsNullOrEmpty(data)) { return(Json(ajax)); } FollowRecord obj = (FollowRecord)(JsonConvert.DeserializeObject(data.ToString(), typeof(FollowRecord))); obj.FollowTime = DateTime.Now; obj.FollowPersonID = UserSession.userid; if (AppointmentData.AddFollow(obj))//注意时间类型 { ajax.msg = "跟进成功!"; ajax.status = EnumAjaxStatus.Success; } return(Json(ajax)); }
/// <summary> /// 读取Excel到数据库 耦合度极高 /// </summary> /// <returns></returns> public bool ExcelToDataBase() { FileStream fs = new FileStream(_filename, FileMode.Open, FileAccess.Read); if (_filename.IndexOf(".xlsx") > 0) { _workbook = new XSSFWorkbook(fs); } else if (_filename.IndexOf(".xls") > 0) { _workbook = new HSSFWorkbook(fs); } // 遍历所有worksheets #region 遍历所有worksheets for (int i = 0; i < _workbook.NumberOfSheets; i++) { _currentSheet = _workbook.GetSheetAt(i); // 处理表头 // 获取表头各项 先导入前18项 // 后面的跟进项要跟数据库的Follow表对比 数据库有则直接入库 没有则新建Follow项 再入库 // 表头 IRow firstRow = _currentSheet.GetRow(0); // 判断数据表的第一行数据是不是为空 // 如果为空 则跳出循环 // 如果不为空 则加载数据 if (firstRow == null) { break; } // 总列数 int columnCount = firstRow.LastCellNum; // 获取当前的跟进项列表 List <Follow> currentFollowList = _followBLL.GetAllFollow().ToList(); for (int k = 21; k < columnCount; k++) { if (currentFollowList.SingleOrDefault(n => n.FollowItem == firstRow.GetCell(k).StringCellValue) == null) { Follow follow = new Follow(); follow.Id = Guid.NewGuid(); follow.FollowItem = firstRow.GetCell(k).StringCellValue; _followBLL.Add(follow); } } // 刷新当前跟进项的纪录 currentFollowList = _followBLL.GetAllFollow().ToList(); // 先处理前18列 前18列是固定列 // 时间 收集员 客户姓名 性别 年龄 婚否 子女 电话 qq 微信 邮箱 地址省市 所有行业 职业 年收入 爱好 是否有车 是否有房 for (int j = 1; j < _currentSheet.LastRowNum + 1; j++) { Information infor = new Information(); IRow _row = _currentSheet.GetRow(j); if (string.IsNullOrEmpty(_row.GetCell(1).StringCellValue.ToString())) { break; } // 构造Information #region 构造Information infor.Id = Guid.NewGuid(); try { infor.InserTime = DateTime.Parse(_row.GetCell(0).DateCellValue.ToString()).ToString("yyyy-mm-dd"); } catch (Exception) { infor.InserTime = DateTime.Parse(_row.GetCell(0).StringCellValue.ToString()).ToString("yyyy-mm-dd"); } Member member = _memberBLL.GetMemberByAccount(_row.GetCell(1).StringCellValue); if (member == null) { return(false); } else { infor.MemberId = Guid.Parse(member.Id.ToString()); } infor.CustomerName = _row.GetCell(2).StringCellValue; infor.Sex = _row.GetCell(3).StringCellValue; try { infor.Age = _row.GetCell(4).NumericCellValue.ToString(); } catch (Exception) { infor.Age = _row.GetCell(4).StringCellValue.ToString(); } infor.IsMarry = _row.GetCell(5).StringCellValue; infor.Children = _row.GetCell(6).StringCellValue; infor.Phone = _row.GetCell(7).StringCellValue; try { infor.QQ = _row.GetCell(8).NumericCellValue.ToString(); } catch (Exception) { infor.QQ = _row.GetCell(8).StringCellValue.ToString(); } infor.WebCat = _row.GetCell(9).StringCellValue; infor.Email = _row.GetCell(10).StringCellValue; infor.Address = _row.GetCell(11).StringCellValue; infor.Industry = _row.GetCell(12).StringCellValue; infor.Occupation = _row.GetCell(13).StringCellValue; try { infor.Income = _row.GetCell(14).NumericCellValue.ToString(); } catch (Exception) { infor.Income = _row.GetCell(14).StringCellValue.ToString(); } infor.Hobby = _row.GetCell(15).StringCellValue; infor.HasCar = _row.GetCell(16).StringCellValue; infor.HasHouse = _row.GetCell(17).StringCellValue; infor.Note1 = _row.GetCell(18).StringCellValue; infor.Note2 = _row.GetCell(19).StringCellValue; infor.Note3 = _row.GetCell(20).StringCellValue; #endregion // 添加Information #region 添加Information if (_informationBLL.Add(infor)) { // 添加成功 for (int k = 21; k < columnCount; k++) { // 循环剩下的跟进项列 // 构造每个FollowRecord FollowRecord fr = new FollowRecord(); fr.Id = Guid.NewGuid(); fr.InforId = infor.Id; fr.FollowId = _followBLL.GetFollow(firstRow.GetCell(k).StringCellValue).Id; fr.FollowValue = _row.GetCell(k).StringCellValue; try { // 添加新的FollowRecord _followRecordBLL.Add(fr); } catch (Exception ex) { LogHelper.Log.Write(ex.Message); LogHelper.Log.Write(ex.StackTrace); //释放内存 fs.Dispose(); return(false); } } } else { // 添加Information 失败 #region 失败后的代码 // 释放内存 fs.Dispose(); return(false); #endregion } #endregion } } #endregion // 如果什么都正常 则返回True return(true); }
public bool Update(FollowRecord follow) { return(_followRecordDAL.Update(follow)); }
public bool Add(FollowRecord follow) { return(_followRecordDAL.Insert(follow)); }
public ActionResult ImportData() { if (Request.IsAjaxRequest()) { var stream = HttpContext.Request.InputStream; string json = new StreamReader(stream).ReadToEnd(); try { //JArray jarray = (JArray)JsonConvert.DeserializeObject(json); List <KeyValuePair <string, string> > kvList = JsonToList(json); Information infor = new Information(); #region 给information赋值 infor.Address = kvList.Where(n => n.Key == "address").SingleOrDefault().Value; infor.Age = kvList.SingleOrDefault(n => n.Key == "age").Value; infor.Children = kvList.SingleOrDefault(n => n.Key == "children").Value; infor.CustomerName = kvList.SingleOrDefault(n => n.Key == "customerName").Value; infor.Email = kvList.SingleOrDefault(n => n.Key == "email").Value; infor.HasCar = kvList.SingleOrDefault(n => n.Key == "hascar").Value; infor.HasHouse = kvList.SingleOrDefault(n => n.Key == "hashouse").Value; infor.Hobby = kvList.SingleOrDefault(n => n.Key == "hobby").Value; infor.Id = Guid.NewGuid(); infor.Income = kvList.SingleOrDefault(n => n.Key == "income").Value; infor.Industry = kvList.SingleOrDefault(n => n.Key == "industry").Value; infor.InserTime = DateTime.Now.ToString("yyyy-MM-dd"); infor.IsMarry = kvList.SingleOrDefault(n => n.Key == "ismarry").Value; infor.MemberId = _memberBLL.GetMemberByAccount(System.Web.HttpContext.Current.Session["Admin"].ToString(), 1).Id; infor.Occupation = kvList.SingleOrDefault(n => n.Key == "occupation").Value; infor.Phone = kvList.SingleOrDefault(n => n.Key == "phone").Value; infor.QQ = kvList.SingleOrDefault(n => n.Key == "qq").Value; infor.Sex = kvList.SingleOrDefault(n => n.Key == "sex").Value; infor.WebCat = kvList.SingleOrDefault(n => n.Key == "webcat").Value; infor.Note1 = kvList.SingleOrDefault(n => n.Key == "note1").Value; infor.Note2 = kvList.SingleOrDefault(n => n.Key == "note2").Value; infor.Note3 = kvList.SingleOrDefault(n => n.Key == "note3").Value; #endregion #region 添加FollowRecord if (_informationBLL.Add(infor)) { List <Follow> followList = _followBLL.GetAllFollow().ToList(); foreach (var item in followList) { FollowRecord fr = new FollowRecord(); fr.FollowId = _followBLL.GetFollow(item.FollowItem).Id; fr.InforId = infor.Id; fr.Id = Guid.NewGuid(); fr.FollowValue = kvList.SingleOrDefault(n => n.Key == item.FollowItem).Value; _followRecordBLL.Add(fr); } return(Json("True", JsonRequestBehavior.AllowGet)); } else { return(Json("False", JsonRequestBehavior.AllowGet)); } #endregion } catch (Exception ex) { LogHelper.Log.Write(ex.Message); LogHelper.Log.Write(ex.StackTrace); return(Json("False", JsonRequestBehavior.AllowGet)); } } else { return(Json("False", JsonRequestBehavior.AllowGet)); } }
public ActionResult Update() { if (Request.IsAjaxRequest()) { var stream = HttpContext.Request.InputStream; string json = new StreamReader(stream).ReadToEnd(); try { //JArray jarray = (JArray)JsonConvert.DeserializeObject(json); List <KeyValuePair <string, string> > kvList = JsonToList(json); Information infor = _informationBLL.GetInformationById(Guid.Parse(kvList.SingleOrDefault(n => n.Key == "id").Value)); #region 给information赋值 infor.Address = kvList.Where(n => n.Key == "address").SingleOrDefault().Value; infor.Age = kvList.SingleOrDefault(n => n.Key == "age").Value; infor.Children = kvList.SingleOrDefault(n => n.Key == "children").Value; infor.Email = kvList.SingleOrDefault(n => n.Key == "email").Value; infor.HasCar = kvList.SingleOrDefault(n => n.Key == "hascar").Value; infor.HasHouse = kvList.SingleOrDefault(n => n.Key == "hashouse").Value; infor.Hobby = kvList.SingleOrDefault(n => n.Key == "hobby").Value; infor.Income = kvList.SingleOrDefault(n => n.Key == "income").Value; infor.Industry = kvList.SingleOrDefault(n => n.Key == "industry").Value; infor.IsMarry = kvList.SingleOrDefault(n => n.Key == "ismarry").Value; infor.Occupation = kvList.SingleOrDefault(n => n.Key == "occupation").Value; infor.Phone = kvList.SingleOrDefault(n => n.Key == "phone").Value; infor.QQ = kvList.SingleOrDefault(n => n.Key == "qq").Value; infor.Sex = kvList.SingleOrDefault(n => n.Key == "sex").Value; infor.WebCat = kvList.SingleOrDefault(n => n.Key == "webcat").Value; infor.Note1 = kvList.SingleOrDefault(n => n.Key == "note1").Value; infor.Note2 = kvList.SingleOrDefault(n => n.Key == "note2").Value; infor.Note3 = kvList.SingleOrDefault(n => n.Key == "note3").Value; #endregion #region 添加FollowRecord if (_informationBLL.Update(infor)) { // 修改information 成功后 // 获取当前FollowRecord中 inforid == 刚才的infor.id的 跟进项列表 List <FollowRecord> frList = _followRecordBLL.GetFollowRecordByInformationId(infor.Id).ToList(); // 获取当前所有的跟进项 // 由于存在 跟进项表中新添加了跟进项 而 FollowRecord 中没有更新 这样的情况 // 所以 有时 frList 的项 会比 followList 的项会少 // 所以在更新followrecord时 要先判断 操作的 FollowRecord 是否为空 // 如果为空则新添加 followrecord 如果不为空 则更新原来的数据 List <Follow> followList = _followBLL.GetAllFollow().ToList(); // 开始更新跟进项 foreach (var item in followList) { // 这里 keyvaluepair<string,string> 的项数 一定是和 followList的项数相等的 // 所以不从这里判断是否有新的跟进项 KeyValuePair <string, string> kvp = kvList.SingleOrDefault(n => n.Key == item.FollowItem); FollowRecord fr = frList.SingleOrDefault(n => n.FollowId == item.Id); if (fr == null) { fr = new FollowRecord(); fr.Id = Guid.NewGuid(); fr.FollowId = item.Id; fr.InforId = infor.Id; fr.FollowValue = kvp.Value; _followRecordBLL.Add(fr); } else { fr.FollowValue = kvp.Value; _followRecordBLL.Update(fr); } } return(Json("True", JsonRequestBehavior.AllowGet)); } else { return(Json("False", JsonRequestBehavior.AllowGet)); } #endregion } catch (Exception ex) { LogHelper.Log.Write(ex.Message); LogHelper.Log.Write(ex.StackTrace); return(Json("False", JsonRequestBehavior.AllowGet)); } } else { return(Json("False", JsonRequestBehavior.AllowGet)); } }
public IActionResult GetHomePage(long UserId, long MyId) { User user = db.Users.FirstOrDefault(s => s.Id == UserId); IDatabase redisDatabase = RedisHelper.Value.Database; string TalkNumber_Key = "UserId=" + UserId.ToString() + "&TalkNumber"; ParamHelper paramHelper = new ParamHelper(); StockAccount stockAccount = db.StockAccounts.FirstOrDefault(s => s.UserId == user.Id); if (MyId == UserId) { return(Json(new { user.Id, user.Username, user.Remark, Gender = user.Gender.ToString(), StockAge = user.StockAge, user.ImageUrl, user.FansNumber, user.FollowNumber, user.CoinNumber, TalkNumber = redisDatabase.StringGet(TalkNumber_Key), SumMoney = stockAccount == null ? "0" : ParamHelper.ConvertNumber(stockAccount.SumMoney) })); } else { FollowRecord followRecord = db.FollowRecords.FirstOrDefault(s => s.FollowingId == MyId && s.FollowedId == UserId); if (followRecord == null) { return(Json(new { user.Id, user.Username, user.Remark, Gender = user.Gender.ToString(), StockAge = user.StockAge, user.ImageUrl, user.FansNumber, user.FollowNumber, user.CoinNumber, TalkNumber = redisDatabase.StringGet(TalkNumber_Key), SumMoney = stockAccount == null ? "0" : ParamHelper.ConvertNumber(stockAccount.SumMoney), If_Follow = "false" })); } else { return(Json(new { user.Id, user.Username, user.Remark, Gender = user.Gender.ToString(), StockAge = user.StockAge, user.ImageUrl, user.FansNumber, user.FollowNumber, user.CoinNumber, TalkNumber = redisDatabase.StringGet(TalkNumber_Key), SumMoney = stockAccount == null ? "0" : ParamHelper.ConvertNumber(stockAccount.SumMoney), If_Follow = "true" })); } } }