/// <summary> /// 修改用户 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <StatusResult> UpdateAsync(UserUpdateInputDto input) { var user = await _userRepository.Select.Where(o => o.Id == input.Id).FirstAsync(); if (user == null) { return(new StatusResult("用户不存在!")); } var thisUser = new UserEntity() { Id = input.Id }; _userRepository.Attach(thisUser); thisUser.Avatar = input.Avatar; thisUser.NickName = input.NickName; thisUser.Phone = input.Phone; thisUser.RealName = input.RealName; int res = await _userRepository.UpdateAsync(thisUser); await _userRoleRepository.DeleteAsync(o => o.UserId == user.Id); var userRoles = input.RoleIds.Select(o => new UserRoleEntity() { RoleId = o.key, UserId = user.Id, Id = Snowflake.GenId() }); await _userRoleRepository.InsertAsync(userRoles); return(new StatusResult(res == 0, "修改失败")); }
public async Task <Routes> UpdateAsync(Routes model) { // model.IsUpdated = true; // ObjectValidation(model); var dbobj = await GetByIdAsync(model.Id); if (dbobj == null) { throw new ProjectException("The Record does not exist in the system"); } dbobj.CardPAN = model.CardPAN; dbobj.Description = model.Description; dbobj.Name = model.Name; if (model.SinkNode != null) { dbobj.SinkNode.HostName = model.SinkNode.HostName; dbobj.SinkNode.IPAdress = model.SinkNode.IPAdress; dbobj.SinkNode.Name = model.SinkNode.Name; dbobj.SinkNode.Port = model.SinkNode.Port; } _ModelRepository.Attach(dbobj, EntityStatus.Modified); await _UnitOfWork.SaveChangesAsync(); return(dbobj); }
public void Add(Encounter encounter) { Validate(encounter); repository.Attach(encounter); repository.Insert(encounter); repository.Save(); }
public void Attach(TEntity entity, bool markDirty = false) { if (entity != null) { _repository.Attach(entity, markDirty); } }
private void btn退回_Click(object sender, EventArgs e) { 车辆作业 clzy = m_clzy; using (IRepository rep = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository <车辆作业>()) { rep.Attach(clzy); foreach (var i in clzy.专家任务.任务) { if (i.任务号 == clzy.最新作业状态.异常参数) { m_dao2.撤销专家任务(clzy.专家任务, i); break; } } } m_处理 = 1; DateTime?通知时间 = System.DateTime.Now; string msg = "动态任务追加失败"; if (m_dm.DataControls["理由"].SelectedDataValue != null) { msg += ":" + m_dm.DataControls["理由"].SelectedDataValue.ToString(); } m_dao.处理作业异常(m_clzy, msg, 通知时间, true); this.DialogResult = System.Windows.Forms.DialogResult.OK; }
public bool Edit(Category category) { bool success; _logger.Info("Start Editing"); try { repoCategory.Attach(category); _uow.SaveChange(); success = true; } catch (Exception ex) { _logger.Error(ex, "Error"); success = false; } if (success == true) { _logger.Info("successfull Edited category"); } else { _logger.Info("failed to Edit"); } _logger.Info("End Edit a Category"); return(success); }
public TaskResponses PutTask(int id, Task_DTO taskDto) { TaskResponses response = new TaskResponses(); try { var task = _taskRepository.Get(x => x.Id == id); if (id != taskDto.TaskId || task == null) { response.status = ResponseErrors.resource_not_found_at_specified_endpoint.ToString(); } else { task.Name = taskDto.Name; task.Description = taskDto.Description; task.DueDate = taskDto.DueDate; _taskRepository.Attach(task); response.status = ResponseStatus.success.ToString(); } return(response); } catch (Exception ex) { response.status = ResponseErrors.internal_server_error.ToString(); response.error_messages.Add(ex.Message); return(response); } }
public Invoice RegisterPayment(Invoice invoice) { //Invoice savedInvoice; try { foreach (var payment in invoice.Payments) { payment.CreatedAt = DateTime.Now; payment.CreatedBy = LoggedUser.UserId; } //Save invoice with details and payments _invoiceRepo.Attach(invoice); _UoW.Complete(); //Register transactions and update stock //savedInvoice = _invoiceRepo.GetAll().Last(); RegisterInventoryTransaction(invoice); } catch (Exception e) { throw e; } return(invoice); }
public bool update(LOAI entity) { if (validate(entity)) { return(loairepository.Attach(entity)); } return(false); }
public bool update(PHIEUNHAPHANG entity) { if (validate(entity)) { return(phieunhaphangrepository.Attach(entity)); } return(false); }
public void AttachSportTest() { var sport = new Sport(); repository.Attach(sport); repository.Save(); Assert.IsTrue(context.Entry(sport).State == EntityState.Unchanged); }
public bool update(SANPHAM entity) { if (validate(entity)) { return(sanphamrepository.Attach(entity)); } return(false); }
public async Task <T> UpdateAsync(T model) { // model.IsUpdated = true; // ObjectValidation(model); var dbobj = await GetByIdAsync(Guid.Parse(model.GetType().GetField("Id").GetValue(T).ToString())); if (dbobj == null) { throw new ProjectException("The Record does not exist in the system"); } _ModelRepository.Attach(dbobj, EntityStatus.Modified); await _UnitOfWork.SaveChangesAsync(); return(dbobj); }
public bool update(NHANVIEN entity) { if (validate(entity)) { return(nhanvienrepository.Attach(entity)); } return(false); }
public bool update(tour entity) { if (validate(entity)) { return(tour.Attach(entity)); } return(false); }
public bool update(NHACUNGCAP entity) { if (validate(entity)) { return(nhacungcaprepository.Attach(entity)); } return(false); }
public async Task <TransLogs> UpdateAsync(TransLogs model) { // model.IsUpdated = true; // ObjectValidation(model); var dbobj = await GetByIdAsync(model.Id); if (dbobj == null) { throw new ProjectException("The Record does not exist in the system"); } _ModelRepository.Attach(dbobj, EntityStatus.Modified); await _UnitOfWork.SaveChangesAsync(); return(dbobj); }
/// <summary> /// delete item's children (whole collection) helper /// </summary> /// <typeparam name="T">StorageEntity</typeparam> /// <param name="sourceCollection"></param> /// <param name="repository"></param> public static void DeleteCollectionItems <T>(this ICollection <T> sourceCollection, IRepository repository) where T : StorageEntity { sourceCollection.ToList().ForEach(x => { repository.Attach(x); repository.Remove(x); sourceCollection.Remove(x); }); }
public ActionResult Edit(User user) { if (ModelState.IsValid) { repository.Attach(user); repository.Commit(); return(RedirectToAction("Index")); } return(View(user)); }
public Task Handle(CreatePostCommand command) { var author = new ApplicationUser { Id = command.AuthorId.ToString() }; var post = new Post(command.Content, author, command.BannerImageUrl); _postRepository.Attach(author); return(_postRepository.Create(post)); }
public JsonResult UpdateStock(Stock model) { var stock = _stockRepository.GetById(model.StockId); _stockRepository.Attach(stock); stock.InjectFrom(model); _stockRepository.SaveChanges(); return(Json(new { success = true }, JsonRequestBehavior.AllowGet)); }
public bool update(TONKHO entity) { if (entity.STT != 0) { if (validate(entity)) { return(tonkhorepository.Attach(entity)); } } return(false); }
public async Task <Fees> UpdateAsync(Fees model) { // model.IsUpdated = true; // ObjectValidation(model); var dbobj = await GetByIdAsync(model.Id); if (dbobj == null) { throw new ProjectException("The Record does not exist in the system"); } dbobj.Name = model.Name; dbobj.FlatAmount = model.FlatAmount; dbobj.Maximum = model.Maximum; dbobj.Minimum = model.Minimum; dbobj.Percent = model.Percent; _ModelRepository.Attach(dbobj, EntityStatus.Modified); await _UnitOfWork.SaveChangesAsync(); return(dbobj); }
public async Task <SourceNode> UpdateAsync(SourceNode model) { // model.IsUpdated = true; // ObjectValidation(model); var dbobj = await GetByIdAsync(model.Id); if (dbobj == null) { throw new ProjectException("The Record does not exist in the system"); } dbobj.HostName = model.HostName; dbobj.IPAdress = model.IPAdress; dbobj.Name = model.Name; dbobj.Port = model.Port; dbobj.Status = model.Status; _ModelRepository.Attach(dbobj, EntityStatus.Modified); await _UnitOfWork.SaveChangesAsync(); return(dbobj); }
public async Task <RefreshTokenEntity> CreateRefreshToken(User user, string ipAddress) { var refreshToken = GenerateRefreshToken(ipAddress); _logger.LogInformation("Creating refresh token for user {UserId}", user?.Id); user = _usersRepo.Attach(user); refreshToken.User = user; await RemoveOldRefreshTokens(user); await _refreshTokensRepo.Add(refreshToken); return(refreshToken); }
public void SaveChanges() { IsEditMode = false; if (Client.IsNew == true) { _repository.Add(Client.ToDbModel()); Messenger.Default.Send(new UpdateClientMsg() { Client = Client }); } else { var client = Client.ToDbModel(); _repository.Attach(client); //var phoneRepo = _unitOfWork.Repository<PhoneE>(); //foreach(var p in client.Phones) //{ // phoneRepo.Attach(p); //} //foreach (var p in client.Phones) //{ // client.Phones.Remove(p); //} //_repositor //var phones = client.Phones; //var equipment = client.Equimpents; //_unitOfWork.Save(); //foreach (var p in _phonesForDelete.Select(p => p.ToDbModel()).Where(p => p.Id != 0)) //{ // phoneRepo.Attach(p); //} //_unitOfWork.Save(); //_phonesForDelete.Clear(); //_unitOfWork.Repository<EquimpentParamE>().DeleteRange(equipment.Where(e => e.Id != 0)); //foreach (var p in phones) // client.Phones.Add(p); //foreach (var e in equipment) // client.Equimpents.Add(e); } _unitOfWork.Save(); }
public static void Delete <T>(this IRepository <T> rs, int id) where T : BaseEntity { Guard.ArgumentNotZero(id, "id"); // Perf: work with stub entity var entity = rs.Create(); entity.Id = id; rs.Attach(entity); // must downcast 'cause of Rhino mocks stub rs.Context.ChangeState((BaseEntity)entity, System.Data.Entity.EntityState.Deleted); }
public void Crawl(Feed feed) { try { _feeds.Attach(feed); feed.LastUpdatedDate = DateTime.Now; var items = _feedReader.LoadItems(feed.Link); if (items == null) { return; } var loadedItemsLinks = items.Select(x => x.Link); var processedItemsLinks = _feedItems.Where(item => loadedItemsLinks.Contains(item.Link)).Select(x => x.Link).ToArray(); var unprocessedItems = items.Where(item => !processedItemsLinks.Contains(item.Link)); foreach (var feedItem in unprocessedItems) { _feedItems.Add(feedItem); feedItem.Description = _htmlConverter.ToPlainText(feedItem.Summary); feedItem.Language = _languageIdentifier.Identify(feedItem.FullText); feedItem.CreatedDate = DateTime.Now; feedItem.Feed = feed; } feed.Status = FeedStatus.Success; } catch (Exception e) { feed.Status = FeedStatus.Failure; Trace.TraceError("An error occured when crawling feed {0}: {1}", feed.Link, e.Message); } try { _unitOfWork.SaveChanges(); } catch (Exception e) { Trace.TraceError(e.Message); } }
public bool Edit(Product product) { try { _ProductRepo.Attach(product); _uow.SaveChange(); return(true); } catch (Exception ex) { _logger.Error(ex, "Error"); return(false); } }
public ActionResult Edit(Trip trip) { if (trip.UserID != provider.AuthenticatedUser.UserID) { throw new UnauthorizedAccessException("Trip doesn't belong to user"); } if (ModelState.IsValid) { repository.Attach(trip); repository.Commit(); return(RedirectToAction("Index")); } return(View(trip)); }
private static void SyncBrokers(HttpClient httpClient, IRepository consoleRepository) { DatabaseInit._LogHandler.WriteLog("SyncBrokers()", LogSeverity.Information, LogCategory.DataAccess); var response = httpClient.GetAsync("rest/api/broker").Result; if (response.IsSuccessStatusCode) { var serviceBrokers = response.Content.ReadAsAsync<IEnumerable<Validus.Services.Models.Broker>>().Result; foreach (var serviceBroker in serviceBrokers) { if (!consoleRepository.Query<Broker>().Any(cb => cb.BrokerSequenceId == serviceBroker.Id)) { consoleRepository.Add(new Broker { BrokerSequenceId = serviceBroker.Id, Name = serviceBroker.Name, Code = serviceBroker.Code, Psu = serviceBroker.Psu, GroupCode = serviceBroker.GrpCd }); } else { var consoleBroker = consoleRepository.Query<Broker>() .FirstOrDefault(cb => cb.BrokerSequenceId == serviceBroker.Id); if (consoleBroker != null) { consoleBroker.Code = serviceBroker.Code; consoleBroker.GroupCode = serviceBroker.GrpCd; consoleBroker.Name = serviceBroker.Name; consoleBroker.Psu = serviceBroker.Psu; consoleRepository.Attach(consoleBroker); } } } } else { DatabaseInit._LogHandler.WriteLog("Get rest/api/broker failed", LogSeverity.Warning, LogCategory.DataAccess); } }
public void Update(BusinessObjects.Model entity) { using (_ModelRepository = new GenericRepository<DAL.DataEntities.Model>()) { entity.LastModifiedDate = DateTime.Now; // _ModelRepository.Attach((DAL.DataEntities.Model)entity.InnerEntity); _ModelRepository.SaveChanges(); } }
public void Update(BLL.BusinessObjects.UITemplate entity) { using (_UITemplateRepository = new GenericRepository<DAL.DataEntities.UITemplate>()) { entity.LastModifiedDate = DateTime.Now; // _UITemplateRepository.Attach((DAL.DataEntities.UITemplate)entity.InnerEntity); _UITemplateRepository.SaveChanges(); } }
public void Update(BusinessObjects.Attribute entity) { using (_AttributeRepository = new GenericRepository<DAL.DataEntities.Attribute>()) { //Update the Attribute _AttributeRepository.Attach((DAL.DataEntities.Attribute)entity.InnerEntity); _AttributeRepository.SaveChanges(); } }
public void Update(BusinessObjects.Configuration entity) { using (_ConfigurationRepository = new GenericRepository<DAL.DataEntities.Configuration>()) { entity.LastModifiedDate = DateTime.Now; // _ConfigurationRepository.Attach((DAL.DataEntities.Configuration)entity.InnerEntity); _ConfigurationRepository.SaveChanges(); } }
public void Update(BusinessObjects.Relation entity) { using (_RelationRepository = new GenericRepository<DAL.DataEntities.Relation>()) { // _RelationRepository.Attach((DAL.DataEntities.Relation)entity.InnerEntity); _RelationRepository.SaveChanges(); } }
public void Update(BusinessObjects.Constraint entity) { using (_ConstraintRepository = new GenericRepository<DAL.DataEntities.Constraint>()) { // _ConstraintRepository.Attach((DAL.DataEntities.Constraint)entity.InnerEntity); _ConstraintRepository.SaveChanges(); } }
private static void SyncNonLondonBrokers(HttpClient httpClient, IRepository consoleRepository) { DatabaseInit._LogHandler.WriteLog("SyncNonLondonBrokers()", LogSeverity.Information, LogCategory.DataAccess); var responseOffices = httpClient.GetAsync("rest/api/office").Result; if (responseOffices.IsSuccessStatusCode) { var serviceOffices = responseOffices.Content.ReadAsAsync<IEnumerable<Validus.Services.Models.Office>>().Result; foreach (var serviceOffice in serviceOffices) { DatabaseInit._LogHandler.WriteLog("SyncNonLondonBrokers()_" + serviceOffice.Code, LogSeverity.Information, LogCategory.DataAccess); var responseNonLondonBroker = httpClient.GetAsync("rest/api/NonLondonBroker?office=" + serviceOffice.Code).Result; if (responseNonLondonBroker.IsSuccessStatusCode) { var serviceNonLondonBrokers = responseNonLondonBroker.Content.ReadAsAsync<IEnumerable<Validus.Services.Models.NonLondonBroker>>().Result; foreach (var serviceNonLondonBroker in serviceNonLondonBrokers) { if (serviceNonLondonBroker.Code == "NA") continue; if (!consoleRepository.Query<NonLondonBroker>().Any(cb => cb.Code == serviceNonLondonBroker.Code)) { consoleRepository.Add(new NonLondonBroker { Name = serviceNonLondonBroker.Name, Code = serviceNonLondonBroker.Code, }); } else { var consoleNonLondonBroker = consoleRepository.Query<NonLondonBroker>() .FirstOrDefault(cb => cb.Code == serviceNonLondonBroker.Code); if (consoleNonLondonBroker != null) { consoleNonLondonBroker.Code = serviceNonLondonBroker.Code; consoleNonLondonBroker.Name = serviceNonLondonBroker.Name; consoleRepository.Attach(consoleNonLondonBroker); } } } } else { DatabaseInit._LogHandler.WriteLog("Get rest/api/NonLondonBroker failed_" + serviceOffice.Code, LogSeverity.Warning, LogCategory.DataAccess); } } if (!consoleRepository.Query<NonLondonBroker>().Any(cb => cb.Code == "NA")) { consoleRepository.Add(new NonLondonBroker { Name = "Not Applicable", Code = "NA", }); } } else { DatabaseInit._LogHandler.WriteLog("Get rest/api/NonLondonBroker failed", LogSeverity.Warning, LogCategory.DataAccess); } }
public void Update(BusinessObjects.Feature entity) { using (_FeatureRepository = new GenericRepository<DAL.DataEntities.Feature>()) { //Update the Feature _FeatureRepository.Attach((DAL.DataEntities.Feature)entity.InnerEntity); _FeatureRepository.SaveChanges(); } }
public void Update(BusinessObjects.FeatureSelection entity) { using (_FeatureSelectionRepository = new GenericRepository<DAL.DataEntities.FeatureSelection>()) { //Update the FeatureSelection _FeatureSelectionRepository.Attach((DAL.DataEntities.FeatureSelection)entity.InnerEntity); _FeatureSelectionRepository.SaveChanges(); //Update AttributeValues using (_AttributeValuesRepository = new GenericRepository<DAL.DataEntities.AttributeValue>()) { for (int i = entity.AttributeValues.Count - 1; i >= 0; i--) { BLL.BusinessObjects.AttributeValue BLLAttributeValue = entity.AttributeValues[i]; BLLAttributeValue.FeatureSelectionID = entity.ID; //Add if (BLLAttributeValue.ToBeDeleted == false && BLLAttributeValue.ID == 0) { _AttributeValuesRepository.Add((DAL.DataEntities.AttributeValue)BLLAttributeValue.InnerEntity); } //Update else if (BLLAttributeValue.ToBeDeleted == false && BLLAttributeValue.ID != 0) { _AttributeValuesRepository.Attach((DAL.DataEntities.AttributeValue)BLLAttributeValue.InnerEntity); } } _AttributeValuesRepository.SaveChanges(); } } }
public void Update(BusinessObjects.CustomRule entity) { using (_CustomRuleRepository = new GenericRepository<DAL.DataEntities.CustomRule>()) { // _CustomRuleRepository.Attach((DAL.DataEntities.CustomRule)entity.InnerEntity); _CustomRuleRepository.SaveChanges(); } }
private static void SyncUnderwriters(HttpClient httpClient, IRepository consoleRepository) { DatabaseInit._LogHandler.WriteLog("SyncUnderwriters()", LogSeverity.Information, LogCategory.DataAccess); var response = httpClient.GetAsync("rest/api/underwriter").Result; if (response.IsSuccessStatusCode) { var serviceUnderwriters = response.Content.ReadAsAsync<IEnumerable<Validus.Services.Models.Underwriter>>().Result; foreach (var serviceUnderwriter in serviceUnderwriters) { if (!consoleRepository.Query<Underwriter>().Any(cu => cu.Code == serviceUnderwriter.Code)) { consoleRepository.Add(new Underwriter { Code = serviceUnderwriter.Code, Name = serviceUnderwriter.Name }); } else { var consoleUnderwriter = consoleRepository.Query<Underwriter>() .FirstOrDefault(b => b.Code == serviceUnderwriter.Code); if (consoleUnderwriter != null) { consoleUnderwriter.Code = serviceUnderwriter.Code; consoleUnderwriter.Name = serviceUnderwriter.Name; consoleRepository.Attach(consoleUnderwriter); } } } } else { DatabaseInit._LogHandler.WriteLog("Get rest/api/underwriter failed", LogSeverity.Warning, LogCategory.DataAccess); } }
private static void SyncRiskCodes(HttpClient httpClient, IRepository consoleRepository) { DatabaseInit._LogHandler.WriteLog("SyncRiskCodes()", LogSeverity.Information, LogCategory.DataAccess); var response = httpClient.GetAsync("rest/api/riskcode").Result; if (response.IsSuccessStatusCode) { var serviceRisks = response.Content.ReadAsAsync<IEnumerable<Validus.Services.Models.RiskCode>>().Result; foreach (var serviceRisk in serviceRisks) { if (!consoleRepository.Query<RiskCode>() .Any(crc => crc.Code == serviceRisk.Code)) { consoleRepository.Add(new RiskCode { Code = serviceRisk.Code, Name = serviceRisk.Name }); } else { var consoleRisk = consoleRepository.Query<RiskCode>() .FirstOrDefault(crc => crc.Code == serviceRisk.Code); if (consoleRisk != null) { consoleRisk.Code = serviceRisk.Code; consoleRisk.Name = serviceRisk.Name; consoleRepository.Attach(consoleRisk); } } } } else { DatabaseInit._LogHandler.WriteLog("Get rest/api/riskcode failed", LogSeverity.Warning, LogCategory.DataAccess); } }