public bool Import(Models.ImportFootChatModel model) { var error = ""; try { model.CheckIsValid(); var tgTagNames = model.TgTags.Select(p => p.TName).Distinct().ToArray(); var tids = _TagSourceRepository.Entities.Where(p => tgTagNames.Contains(p.name) && p.isEnable).Select(p => p.tid).Distinct().ToArray(); ExceptionHelper.ThrowIfTrue(!tids.Any(), nameof(tids), "足迹标签不能为空"); var tgFid = model.TgFid; var uid = model.Uid; try { AddUser(uid); } catch (System.Exception e) { error = string.Format("添加用户失败:{0}", e.Message); throw new Tgnet.Exception(error); } try { AddFootPrint(model, tids); } catch (System.Exception e) { error = string.Format("添加足迹失败:{0}", e.Message); throw new Tgnet.Exception(error); } return(true); } catch (System.Exception E) { error = E.Message; _ImportFootPrintRecordRepository.Add(new ImportFootPrintRecord() { tgFid = model.TgFid, fid = 0, isSuccess = false, uid = model.Uid, unSuccessReason = error }); _ImportFootPrintRecordRepository.SaveChanges(); return(false); } }
private void AddFootPrint(Models.ImportFootChatModel model, long[] tids) { var tgFid = model.TgFid; var now = DateTime.Now; using (var scope = new TransactionScope()) { if (!CheckExistFootPrint(tgFid)) { var entity = _FootPrintRepository.Add(new Data.FootPrint() { uid = model.Uid, pid = model.Pid, address = model.Adddress, areaNo = model.AreaNo, content = model.Content, latitude = model.Latitude, longitude = model.Longitude, created = now, isEnable = true, state = FootPrintState.None, orderUpdated = now, tgFid = tgFid, updated = now, }); _FootPrintRepository.Add(entity); _FootPrintRepository.SaveChanges(); var fid = entity.fid; var service = _FootPrintServiceFactory.GetService(entity.fid); var imags = (model.Imags ?? new Models.ImportFootPrintImg[0]).Where(p => !string.IsNullOrWhiteSpace(p.Imag)); if (imags.Count() > 0) { service.UpdateImages(imags.Select(p => (Model.FootImageInfo)p).ToArray()); } service.UpdateTags(tids); _ImportFootPrintRecordRepository.Add(new ImportFootPrintRecord() { fid = entity.fid, tgFid = tgFid, isSuccess = true, uid = model.Uid, unSuccessReason = "" }); _ImportFootPrintRecordRepository.SaveChanges(); } scope.Complete(); } }