/// <summary> /// This method assumes that RemoteRepo.Load() was already called. /// </summary> /// <param name="app"></param> /// <returns></returns> public List<RemoteVsLocalFile> GroupFilesByName (string localFoldrPath, IRepository<SyncableFileRemote> repo, SyncDirection syncDirection) { var list = new List<RemoteVsLocalFile>(); var locals = _fileSeeker.GetFiles(localFoldrPath); foreach (var loc in locals) { var rem = repo.One(x => x.Name == loc.Name); list.Add(RemVsLoc(loc, rem, syncDirection)); } foreach (var rem in repo.Any(r => !list.Has(l => l.Filename == r.Name))) { var loc = locals.One(x => x.Name == rem.Name); list.Add(RemVsLoc(loc, rem, syncDirection)); } // if no files in folder, or no folder at all, // - assume that it's a first run : download all // if (locals.Count == 0) list.ForEach(x => x.DoNext(Target.Local, FileTask.Create)); return list; }
public TransactionRequestModule(IRepository<TransactionRequest> transactionRequestRepo) { Get["/Transactions/Request/{requestId}"] = param => { var requestId = new Guid(param.requestId); if (!transactionRequestRepo.Any(x => x.RequestId == requestId && x.ExpirationDate > DateTime.UtcNow)) return Response.AsJson(new { Error = "Request expired" }); if (transactionRequestRepo.Any(x => x.RequestId == requestId && x.UserState == ApiCommitRequestUserState.Cancelled)) return Response.AsJson(new { Error = "Request cancelled by user" }); if (transactionRequestRepo.Any(x => x.RequestId == requestId && x.ExpirationDate > DateTime.UtcNow)) return Response.AsJson(new { Success = "Request valid" }); return Response.AsJson(new { Error = "Technical error" }); }; }
public bool CheckDiscountCode(string code, int boardGameId) { return(discountCodeRepository.Any(dc => dc.Code == code && dc.BoardGameId == boardGameId)); }
public async Task <bool> Exists(Guid id) { return(await _repository.Any(a => a.Id == id)); }
private bool InfrastructureComplexityRateExists(int id) { return(_rates.Any(e => e.ID == id)); }
public bool Any(int id) { return(productionEquipmentRepository.Any(x => x.Id == id)); }
public async Task <Response <PostEntity> > EditPost(EditPostRequest request) { return(await TryExecuteAsync <PostEntity>(async() => { var postModel = _postRepository.Get(request.Id); if (null == postModel) { return new FailedResponse <PostEntity>((int)ResponseFailureCode.PostNotFound); } postModel.CommentEnabled = request.EnableComment; postModel.PostContent = AppSettings.Editor == EditorChoice.Markdown ? request.EditorContent : _htmlCodec.HtmlEncode(request.EditorContent); postModel.ContentAbstract = Utils.GetPostAbstract( request.EditorContent, AppSettings.PostAbstractWords, AppSettings.Editor == EditorChoice.Markdown); // Address #221: Do not allow published posts back to draft status // postModel.PostPublish.IsPublished = request.IsPublished; // Edit draft -> save and publish, ignore false case because #221 bool isNewPublish = false; if (request.IsPublished && !postModel.PostPublish.IsPublished) { postModel.PostPublish.IsPublished = true; postModel.PostPublish.PublisherIp = request.RequestIp; postModel.PostPublish.PubDateUtc = DateTime.UtcNow; isNewPublish = true; } // #325: Allow changing publish date for published posts if (request.PublishDate != null && postModel.PostPublish.PubDateUtc.HasValue) { var tod = postModel.PostPublish.PubDateUtc.Value.TimeOfDay; var adjustedDate = _dateTimeResolver.GetUtcTimeFromUserTZone(request.PublishDate.Value); postModel.PostPublish.PubDateUtc = adjustedDate.AddTicks(tod.Ticks); } postModel.Slug = request.Slug; postModel.Title = request.Title; postModel.PostPublish.ExposedToSiteMap = request.ExposedToSiteMap; postModel.PostPublish.LastModifiedUtc = DateTime.UtcNow; postModel.PostPublish.IsFeedIncluded = request.IsFeedIncluded; postModel.PostPublish.ContentLanguageCode = request.ContentLanguageCode; ++postModel.PostPublish.Revision; // 1. Add new tags to tag lib foreach (var item in request.Tags.Where(item => !_tagRepository.Any(p => p.DisplayName == item))) { _tagRepository.Add(new TagEntity { DisplayName = item, NormalizedName = Utils.NormalizeTagName(item) }); await _moongladeAudit.AddAuditEntry(EventType.Content, EventId.TagCreated, $"Tag '{item}' created."); } // 2. update tags postModel.PostTag.Clear(); if (request.Tags.Any()) { foreach (var tagName in request.Tags) { if (!Utils.ValidateTagName(tagName)) { continue; } var tag = _tagRepository.Get(t => t.DisplayName == tagName); if (tag != null) { postModel.PostTag.Add(new PostTagEntity { PostId = postModel.Id, TagId = tag.Id }); } } } // 3. update categories postModel.PostCategory.Clear(); if (null != request.CategoryIds && request.CategoryIds.Length > 0) { foreach (var cid in request.CategoryIds) { if (_categoryRepository.Any(c => c.Id == cid)) { postModel.PostCategory.Add(new PostCategoryEntity { PostId = postModel.Id, CategoryId = cid }); } } } await _postRepository.UpdateAsync(postModel); await _moongladeAudit.AddAuditEntry( EventType.Content, isNewPublish ? EventId.PostPublished : EventId.PostUpdated, $"Post updated, id: {postModel.Id}"); return new SuccessResponse <PostEntity>(postModel); })); }
public bool Any(Guid id) { return(tvSerieRepository.Any(x => x.Id == id)); }
public bool Any(Guid id) { return(certificateRepository.Any(x => x.Id == id)); }
public bool Any(int id) { return(businessAreaRepository.Any(x => x.Id == id)); }
public bool Any(Expression <Func <T, bool> > filter) { return(_repository.Any(filter)); }
public ActionResult Menu(MenuDto model) { if (ModelState.IsValid) { try { // 菜单时间在今天之前的菜单不可更新 if (model.MenuDate < DateTime.Today) { ModelState.AddModelError("Error", "此菜单日期早于今天,无法添加或修改"); return(View(model)); } // 如存在同天且相同午餐或晚餐的同套餐则提示重复 if (model.ID <= 0 && _repo.Any <Menu>(x => x.MenuDate == model.MenuDate.Value && x.MenuType == (MenuTypeEnum)Enum.Parse(typeof(MenuTypeEnum), model.Name) && // ReSharper disable once RedundantBoolCompare // Shsict.Core.ConditionBuilder x.MenuFlag == model.Flag && x.IsActive == true)) { ModelState.AddModelError("Error", "已存在同一时间段的重复套餐,无法添加"); return(View(model)); } // 如该菜单已有订单,则不能修改,只能删除 // ReSharper disable once RedundantBoolCompare // Shsict.Core.ConditionBuilder if (_repo.Any <Order>(x => x.MenuID == model.ID && x.IsActive == true)) { ModelState.AddModelError("Error", "此菜单已存在订餐申请,无法修改"); return(View(model)); } var menu = _repo.Single <Menu>(model.ID); if (menu != null) { menu = model.MapTo(menu); } else { menu = model.MapTo <MenuDto, Menu>(); menu.CreateUser = _authorizedUser.UserId; menu.CreateTime = DateTime.Now; menu.IsActive = true; menu.Remark = string.Empty; } menu.MenuType = (MenuTypeEnum)Enum.Parse(typeof(MenuTypeEnum), model.Name); menu.MenuFlag = model.Flag; // 更新菜单信息 object key; _repo.Save(menu, out key); Entities.Menu.Cache.RefreshCache(); ModelState.AddModelError("Success", "保存成功"); } catch (Exception ex) { ModelState.AddModelError("Warn", ex.Message); } } return(View(model)); }
public bool Any(Guid id) { return(contactRepository.Any(x => x.Id == id)); }
public bool Any(int id) { return(changeQualityPlanRepository.Any(x => x.Id == id)); }
public bool IsAvailable(int boardGameId) { return(boardGameRepository.Any(bg => bg.BoardGameId == boardGameId && bg.Quantity > 0)); }
public UserAliasModule(IBus bus, IRepository<ClientUserAlias> userAliasRepository, IRepository<User> usereRepository) { Get["/UserAliases/{clientId:guid}"] = _ => { var clientId = (Guid)_.clientId; var aliases = userAliasRepository.Where(x => x.Client.Id == clientId); return Response.AsJson(Mapper.Map<IEnumerable<ClientUserAlias>, IEnumerable<UserAliasDto>>(aliases)); }; //TODO: Error checking for file type. Allow csv only Post["/UserAliases/ImportUsers/FilesUpload/{clientId:guid}"] = _ => { var clientId = (Guid)_.clientId; var filesUploaded = Request.Files; var files = new List<FileUploadDto>(); var clientImportUsers = new List<UserAliasDto>(); foreach (var httpFile in filesUploaded) { //if (httpFile.ContentType != "text/csv") //{ // // Response for file upload component // files.Add(new FileUploadDto // { // name = httpFile.Name, // size = Convert.ToInt32(httpFile.Value.Length), // error = "File type not allowed" // }); // break; //}; // CSV to object using (var reader = new StreamReader(httpFile.Value)) { var contents = reader.ReadToEnd().Split('\n'); var csv = from line in contents select line.Split(',').ToArray(); clientImportUsers.AddRange(csv.Skip(1).TakeWhile(r => r.Length > 1 && r.Last().Trim().Length > 0) .Select(row => new UserAliasDto { UuId = row[0], FirstName = row[1], LastName = row[2], UserName = row[3].Replace("\r", ""), ClientId = clientId })); foreach (var clientImportUser in clientImportUsers) { var exists = userAliasRepository.Any(x => x.Client.Id == clientId && x.UserName.Trim().ToLower() == clientImportUser.UserName.Trim().ToLower()); if (exists) throw new LightstoneAutoException("{0} already exists".FormatWith(clientImportUser.UserName)); var entity = Mapper.Map(clientImportUser, new ClientUserAlias()); bus.Publish(new CreateUpdateEntity(entity, "Create")); } } // Response for file upload component files.Add(new FileUploadDto { name = httpFile.Name, size = Convert.ToInt32(httpFile.Value.Length), thumbnailUrl = "http://icons.iconarchive.com/icons/custom-icon-design/pretty-office-2/72/success-icon.png", deleteType = "DELETE" }); } var fileResponseJsonObject = new JObject(new JProperty("files", JsonConvert.SerializeObject(files))); return Response.AsJson(fileResponseJsonObject); }; Post["/UserAliases/LinkAlias"] = _ => { var dto = this.Bind<AliasDto>(); var command = new LinkUserAliasCommand(dto.AliasId, dto.CustomerId, dto.UserId); bus.Publish(command); return Response.AsJson("Saved!"); }; }
public bool UserExists(string username) { return(_userRepository.Any(p => p.UserName.Equals(username))); }
public bool Any(Guid id) { return(supplierRepository.Any(a => a.Id == id)); }
private bool TestsCoverageLevelExists(int id) { return(_levels.Any(e => e.ID == id)); }
public async Task <Response <PostEntity> > CreateNewPost(CreatePostRequest request) { return(await TryExecuteAsync <PostEntity>(async() => { var postModel = new PostEntity { CommentEnabled = request.EnableComment, Id = Guid.NewGuid(), PostContent = AppSettings.Editor == EditorChoice.Markdown ? request.EditorContent : _htmlCodec.HtmlEncode(request.EditorContent), ContentAbstract = Utils.GetPostAbstract( request.EditorContent, AppSettings.PostAbstractWords, AppSettings.Editor == EditorChoice.Markdown), CreateOnUtc = DateTime.UtcNow, Slug = request.Slug.ToLower().Trim(), Title = request.Title.Trim(), PostPublish = new PostPublishEntity { IsDeleted = false, IsPublished = request.IsPublished, PubDateUtc = request.IsPublished ? DateTime.UtcNow : (DateTime?)null, ExposedToSiteMap = request.ExposedToSiteMap, IsFeedIncluded = request.IsFeedIncluded, Revision = 0, ContentLanguageCode = request.ContentLanguageCode, PublisherIp = request.RequestIp }, PostExtension = new PostExtensionEntity { Hits = 0, Likes = 0 } }; // check if exist same slug under the same day // linq to sql fix: // cannot write "p.PostPublish.PubDateUtc.GetValueOrDefault().Date == DateTime.UtcNow.Date" // it will not blow up, but can result in select ENTIRE posts and evaluated in memory!!! // - The LINQ expression 'where (Convert([p.PostPublish]?.PubDateUtc?.GetValueOrDefault(), DateTime).Date == DateTime.UtcNow.Date)' could not be translated and will be evaluated locally // Why EF Core this diao yang? if (_postRepository.Any(p => p.Slug == postModel.Slug && p.PostPublish.PubDateUtc != null && p.PostPublish.PubDateUtc.Value.Year == DateTime.UtcNow.Date.Year && p.PostPublish.PubDateUtc.Value.Month == DateTime.UtcNow.Date.Month && p.PostPublish.PubDateUtc.Value.Day == DateTime.UtcNow.Date.Day)) { var uid = Guid.NewGuid(); postModel.Slug += $"-{uid.ToString().ToLower().Substring(0, 8)}"; Logger.LogInformation($"Found conflict for post slug, generated new slug: {postModel.Slug}"); } // add categories if (null != request.CategoryIds && request.CategoryIds.Length > 0) { foreach (var cid in request.CategoryIds) { if (_categoryRepository.Any(c => c.Id == cid)) { postModel.PostCategory.Add(new PostCategoryEntity { CategoryId = cid, PostId = postModel.Id }); } } } // add tags if (null != request.Tags && request.Tags.Length > 0) { foreach (var item in request.Tags) { if (!Utils.ValidateTagName(item)) { continue; } var tag = _tagRepository.Get(q => q.DisplayName == item); if (null == tag) { var newTag = new TagEntity { DisplayName = item, NormalizedName = Utils.NormalizeTagName(item) }; tag = _tagRepository.Add(newTag); await _moongladeAudit.AddAuditEntry(EventType.Content, EventId.TagCreated, $"Tag '{tag.NormalizedName}' created."); } postModel.PostTag.Add(new PostTagEntity { TagId = tag.Id, PostId = postModel.Id }); } } await _postRepository.AddAsync(postModel); Logger.LogInformation($"New Post Created Successfully. PostId: {postModel.Id}"); await _moongladeAudit.AddAuditEntry(EventType.Content, EventId.PostCreated, $"Post created, id: {postModel.Id}"); return new SuccessResponse <PostEntity>(postModel); })); }
public bool Any(Guid id) { return(projectRepository.Any(x => x.Id == id)); }
public bool Exist(string username) { var exist = _accountRepo.Any(p => p.Username == username.ToLower()); return(exist); }
public async Task <PingbackResponse> ReceivePingAsync(string requestBody, string ip, Action <PingbackEntity> pingSuccessAction) { try { if (string.IsNullOrWhiteSpace(requestBody)) { _logger.LogError("Pingback requestBody is null"); return(PingbackResponse.GenericError); } var valid = ValidateRequest(requestBody); if (!valid) { return(PingbackResponse.InvalidPingRequest); } _logger.LogInformation($"Processing Pingback from: {_sourceUrl} ({ip}) to {_targetUrl}"); var pingRequest = await _pingSourceInspector.ExamineSourceAsync(_sourceUrl, _targetUrl); if (null == pingRequest) { return(PingbackResponse.InvalidPingRequest); } if (!pingRequest.SourceHasLink) { _logger.LogError("Pingback error: The source URI does not contain a link to the target URI."); return(PingbackResponse.Error17SourceNotContainTargetUri); } if (pingRequest.ContainsHtml) { _logger.LogWarning("Spam detected on current Pingback..."); return(PingbackResponse.SpamDetectedFakeNotFound); } var(slug, pubDate) = GetSlugInfoFromUrl(pingRequest.TargetUrl); var spec = new PostSpec(pubDate, slug); var(id, title) = await _postRepo.SelectFirstOrDefaultAsync(spec, p => new Tuple <Guid, string>(p.Id, p.Title)); if (id == Guid.Empty) { _logger.LogError($"Can not get post id and title for url '{pingRequest.TargetUrl}'"); return(PingbackResponse.Error32TargetUriNotExist); } _logger.LogInformation($"Post '{id}:{title}' is found for ping."); var pinged = _pingbackRepo.Any(p => p.TargetPostId == id && p.SourceUrl == pingRequest.SourceUrl && p.SourceIp.Trim() == ip); if (pinged) { return(PingbackResponse.Error48PingbackAlreadyRegistered); } _logger.LogInformation("Adding received pingback..."); var uri = new Uri(_sourceUrl); var obj = new PingbackEntity { Id = Guid.NewGuid(), PingTimeUtc = DateTime.UtcNow, Domain = uri.Host, SourceUrl = _sourceUrl, SourceTitle = pingRequest.Title, TargetPostId = id, TargetPostTitle = title, SourceIp = ip }; await _pingbackRepo.AddAsync(obj); pingSuccessAction?.Invoke(obj); return(PingbackResponse.Success); } catch (Exception e) { _logger.LogError(e, nameof(ReceivePingAsync)); return(PingbackResponse.GenericError); } }
public bool Any(Guid id) { return(companyRepository.Any(x => x.Id == id)); }
private bool StandardModulesUsingRateExists(int id) { return(_rates.Any(e => e.ID == id)); }
public bool Any(Guid id) { return(feedRepository.Any(x => x.Id == id)); }
/// <summary> /// 处理作业单流程 /// </summary> /// <param name="flow"></param> /// <returns></returns> public ActionResult <bool> FlowResult(OpreateBillFlowResult flow) { try { if (flow == null) { throw new Exception("参数有误"); } if ((int)flow.FlowResult == 0) { throw new Exception("处理结果数据有误"); } var oflow = _work.Repository <Basic_OpreationFlow>().GetModel(q => q.ID == flow.OpreationFlowID); if (oflow == null) { throw new Exception("作业流程节点不存在"); } var opreationflow = _work.Repository <Basic_Opreation>().GetModel(oflow.OpreationID); if (opreationflow == null) { throw new Exception("作业流程不存在"); } if (flow.FlowResult == PublicEnum.OpreateFlowResult.reback && !opreationflow.IsBackReturn) { throw new Exception("作业流和不支持回退"); } var checkflow = rpsBillFlow.Any(q => q.FlowResult == (int)flow.FlowResult && q.OpreationFlowID == flow.OpreationFlowID && q.BillID == flow.BillID); if (checkflow) { throw new Exception("该作业单已经提交了该节点的处理结果"); } var billmodel = rpsOpreateBill.GetModel(flow.BillID); if (billmodel == null) { throw new Exception("业务单据不存在"); } if (billmodel.State != (int)PublicEnum.BillFlowState.audited) { throw new Exception("作业单状态不允许"); } //所有节点集合, IEnumerable <Basic_OpreationFlow> points = JsonConvert.DeserializeObject <IEnumerable <Basic_OpreationFlow> >(billmodel.FlowsJson); bool writbill = false; switch (flow.FlowResult) { case PublicEnum.OpreateFlowResult.stop: //终止 billmodel.State = (int)PublicEnum.BillFlowState.stop; writbill = true; break; case PublicEnum.OpreateFlowResult.over: //完成,如果是最后一步则修改单据状态 var lastpointid = points.OrderByDescending(o => o.PointIndex).FirstOrDefault().ID; if (flow.OpreationFlowID == lastpointid) { billmodel.State = (int)PublicEnum.BillFlowState.Over; writbill = true; } //如果不是最后一步就给下一步推送信息 /******************************发送管处理人信息**************************************/ var nextpoint = points.OrderBy(o => o.PointIndex).FirstOrDefault(p => p.PointIndex > oflow.PointIndex); var empsIds = _work.Repository <Basic_PostEmployees>().Queryable(p => p.PostID == nextpoint.PostID).Select(s => s.EmployeeID); var ctrp = _work.Repository <Basic_Employee>().Queryable(p => empsIds.Contains(p.ID)).Select(s => s.Login); var msgToUsers = _work.Repository <Auth_User>().Queryable(p => ctrp.Contains(p.Login)); foreach (var item in msgToUsers) { //判断是否绑定微信 if (string.IsNullOrEmpty(item.openID)) { continue; } var sendData = new Dictionary <string, MessageDataBase>(); sendData.Add("first", new MessageDataBase { value = "请尽快完成当前节点的类容" }); sendData.Add("keyword1", new MessageDataBase { value = billmodel.BillName }); sendData.Add("keyword2", new MessageDataBase { value = "作业流程" }); sendData.Add("keyword3", new MessageDataBase { value = nextpoint.PointName }); sendData.Add("keyword4", new MessageDataBase { value = billmodel.CreateDate.ToString("yyyy-MM-dd HH:mm:ss") }); sendData.Add("keyword5", new MessageDataBase { value = billmodel.EndTime.ToString("yyyy-MM-dd HH:mm:ss") }); sendData.Add("remark", new MessageDataBase { value = "ESF微服为安全护航。" }); var Msg = new TemplateMessagePara { template_id = "6HzNyomBRZiKo5u-JgJFbr2ygqdQ-n7wq3c5obqQpY0", touser = item.openID, data = sendData, url = "http://weixin.bjjtza.com/MyWork/Doingwork" }; WxService.SendTemplateMessage(Msg); } /************************************************************************/ break; case PublicEnum.OpreateFlowResult.reback: //退回到最后一步时则退回完成 var relastpointid = points.OrderBy(o => o.PointIndex).FirstOrDefault().ID; if (flow.OpreationFlowID == relastpointid) { billmodel.State = (int)PublicEnum.BillFlowState.Reback; writbill = true; } //如果不是最后一步就给上一步推送信息 /******************************发送管处理人信息**************************************/ var lastpoint = points.OrderByDescending(o => o.PointIndex).FirstOrDefault(p => p.PointIndex < oflow.PointIndex); var empsIds1 = _work.Repository <Basic_PostEmployees>().Queryable(p => p.PostID == lastpoint.PostID).Select(s => s.EmployeeID); var ctrp1 = _work.Repository <Basic_Employee>().Queryable(p => empsIds1.Contains(p.ID)).Select(s => s.Login); var msgToUsers1 = _work.Repository <Auth_User>().Queryable(p => ctrp1.Contains(p.Login)); foreach (var item in msgToUsers1) { //判断是否绑定微信 if (string.IsNullOrEmpty(item.openID)) { continue; } var sendData = new Dictionary <string, MessageDataBase>(); sendData.Add("first", new MessageDataBase { value = "请尽快完成当前节点的类容" }); sendData.Add("keyword1", new MessageDataBase { value = billmodel.BillName }); sendData.Add("keyword2", new MessageDataBase { value = "作业流程" }); sendData.Add("keyword3", new MessageDataBase { value = lastpoint.PointName }); sendData.Add("keyword4", new MessageDataBase { value = billmodel.CreateDate.ToString("yyyy-MM-dd HH:mm:ss") }); sendData.Add("keyword5", new MessageDataBase { value = billmodel.EndTime.ToString("yyyy-MM-dd HH:mm:ss") }); sendData.Add("remark", new MessageDataBase { value = "ESF微服为安全护航。" }); var Msg = new TemplateMessagePara { template_id = "6HzNyomBRZiKo5u-JgJFbr2ygqdQ-n7wq3c5obqQpY0", touser = item.openID, data = sendData, url = "http://weixin.bjjtza.com/MyWork/Doingwork" }; WxService.SendTemplateMessage(Msg); } /************************************************************************/ break; default: break; } var dbflow = flow.MAPTO <Bll_OpreateionBillFlow>(); dbflow.BillID = billmodel.ID; dbflow.FlowEmployeeID = AppUser.EmployeeInfo.ID; dbflow.FlowTime = DateTime.Now; dbflow.ID = Guid.NewGuid(); rpsBillFlow.Add(dbflow); if (writbill) { rpsOpreateBill.Update(billmodel); } _work.Commit(); return(new ActionResult <bool>(true)); } catch (Exception ex) { return(new ActionResult <bool>(ex)); } }
private bool NirSoftwareDevLaborGroupExists(int id) { return(_groups.Any(e => e.ID == id)); }
public bool Any(int id) { return(stockLocationRepository.Any(x => x.Id == id)); }
/// <summary> /// 判断分类是否重复。 /// </summary> /// <param name="category">当前分类实例对象。</param> /// <returns>返回判断结果。</returns> protected virtual bool IsDuplicate(TCategory category) { return(Database.Any(c => c.Name == category.Name && c.Id != category.Id)); }
public void SaveTimetableForUser(Timetable timetable) { DateTime dateTimeFriday = timetable.DateTime.AddDays(4); int currentUserId = timetable.WorkingUsers.First().UserId; IEnumerable <Timetable> existingTimetables = timetableRepository.FindBy(t => t.DateTime.Year == timetable.DateTime.Year && t.DateTime.Month == timetable.DateTime.Month && t.DateTime.Day >= timetable.DateTime.Day && t.DateTime.Day <= dateTimeFriday.Day && t.WorkingUsers.Any(u => u.UserId == currentUserId)); foreach (Timetable item in existingTimetables) { timetableRepository.RemoveManyToMany <User>(t => t.TimetableId == item.TimetableId , nameof(timetable.WorkingUsers) , nameof(User.UserId) , new User[] { timetable.WorkingUsers.First() }); } timetableRepository.SaveChanges(); IList <Timetable> newTimetables = new List <Timetable>(); for (int d = timetable.DateTime.Day; d < timetable.DateTime.Day + 5; d++) { for (int h = timetable.DateTime.Hour; h < timetable.DateTime.Hour + 8; h++) { if (!timetableRepository.Any(t => t.DateTime.Year == timetable.DateTime.Year && t.DateTime.Month == timetable.DateTime.Month && t.DateTime.Day == d && t.DateTime.Hour == h)) { Timetable newTimetable = new Timetable { DateTime = new DateTime(timetable.DateTime.Year, timetable.DateTime.Month, d, h, 0, 0), NumberOfEmployeesForCustomer = timetable.NumberOfEmployeesForCustomer, NumberOfEmployeesForManager = timetable.NumberOfEmployeesForManager, NumberOfEmployeesReservedForCustomer = timetable.NumberOfEmployeesReservedForCustomer, NumberOfEmployeesReservedForManager = timetable.NumberOfEmployeesReservedForManager }; newTimetables.Add(newTimetable); } } } if (newTimetables.Count > 0) { timetableRepository.AddRange(newTimetables); timetableRepository.SaveChanges(); } for (int d = timetable.DateTime.Day; d < timetable.DateTime.Day + 5; d++) { for (int h = timetable.DateTime.Hour; h < timetable.DateTime.Hour + 8; h++) { timetableRepository.EditManyToMany <User>(t => t.DateTime.Year == timetable.DateTime.Year && t.DateTime.Month == timetable.DateTime.Month && t.DateTime.Day == d && t.DateTime.Hour == h , nameof(timetable.WorkingUsers) , nameof(User.UserId) , new User[] { timetable.WorkingUsers.First() }); } } timetableRepository.SaveChanges(); }
public bool AlreadyExistsAccount(string numero) { return(cuentasRepository.Any(a => a.Id == numero)); }
/// <summary> /// 数据是否存在 /// </summary> /// <param name="where"></param> /// <returns></returns> public bool Any(Expression <Func <T, bool> > @where = null) { return(_repo.Any(where)); }