public int Add(UserBusinessModel userModel) { var user = UserFromBusinessModel(userModel); _context.Add(user); return(user.UserId); }
public void RegisterNewClient(Client client) { loggerService.RunWithExceptionLogging(() => { dataContext.Add(client); dataContext.SaveChanges(); loggerService.Info($"{client.Name} {client.Surname} client was registered"); }, isSilent: true); }
public override void ArrangeDataContext(IDataContext context) { context.Add(new BlogPost { Id = sampleId, Code = "sample", Name = "Sample Posting" }); context.Add(new BlogPost { Id = testId, Code = "test", Name = "Test Posting" }); context.Add(new BlogPost { Id = exampleId, Code = "example", Name = "Example Posting" }); }
public void CreateProjectCollection(ProjectCollection collection) { ValidateObject(collection); if (context.ProjectCollections.Any(p => p.Name.Equals(collection.Name, StringComparison.OrdinalIgnoreCase))) { throw new BusinessException("A collection with the specified name already exists."); } context.Add(collection); context.Commit(); }
public void RegisterTraider(string fName, string sName, decimal cash, ICollection <Stock> stock = null) { var entity = new Traider { FirstName = fName, SecondName = sName, Balance = cash, Stocks = stock }; Logger.Log.Info("New Traider ---> " + entity.GetInfo()); _dataContext.Add(entity); _dataContext.SaveChanges(); }
public void AddNewClient(string name, string surname, string phoneNumber, decimal balance) { var client = new Client() { Name = name, Surname = surname, PhoneNumber = phoneNumber, Balance = balance, ClientStocks = new List <Stock>() }; dataContext.Add(client); dataContext.SaveChanges(); }
public void RegisterNewClient(string firstName, string lastName, string phoneNamber, decimal balance) { Client client = new Client() { FirstName = firstName, LastName = lastName, PhoneNumber = phoneNamber, Balance = balance, Stocks = new List <Stock>() }; dataContext.Add(client); dataContext.SaveChanges(); }
protected virtual void RestoreViewModel([NotNull] Type viewModelType, [NotNull] IDataContext viewModelState, [NotNull] FrameworkElement element, [NotNull] IDictionary <string, object> state, [NotNull] object args, [NotNull] IDataContext context) { context = context.ToNonReadOnly(); context.AddOrUpdate(InitializationConstants.ViewModelType, viewModelType); #if WINDOWSCOMMON context.Add(DynamicViewModelWindowPresenter.RestoredViewConstant, element); context.Add(DynamicViewModelWindowPresenter.IsOpenViewConstant, true); #endif IViewModel viewModel = _viewModelProvider.RestoreViewModel(viewModelState, context, false); _viewManager.InitializeViewAsync(viewModel, element, context).WithTaskExceptionHandler(this); _viewModelPresenter.Restore(viewModel, context); }
protected virtual void RestoreViewModel([NotNull] Type viewModelType, [NotNull] IDataContext viewModelState, [NotNull] FrameworkElement element, [NotNull] IDictionary <string, object> state, [NotNull] object args, [NotNull] IDataContext context) { context = context.ToNonReadOnly(); context.AddOrUpdate(InitializationConstants.ViewModelType, viewModelType); #if WINDOWS_UWP context.Add(WindowPresenterConstants.RestoredView, element); context.Add(WindowPresenterConstants.IsViewOpened, true); #endif IViewModel viewModel = _viewModelProvider.RestoreViewModel(viewModelState, context, true); context.AddOrUpdate(NavigationConstants.ViewModel, viewModel); _viewManager.InitializeViewAsync(viewModel, element, context); _viewModelPresenter.Restore(context); }
public void AddTrader(string name, string surname, decimal balane, string phoneNumber) { var trader = new Trader() { Balance = balane, Name = name, PhoneNumber = phoneNumber, Surname = surname }; _dataContext.Add(trader); _dataContext.SaveChanges(); _loggerService.Info($"New trader: {name} {surname} with {balane} in account was added"); }
public User CreateUser(string email, string password) { if (email == null) { throw new ArgumentNullException(nameof(email)); } if (password == null) { throw new ArgumentNullException(nameof(password)); } if (password.Length < 6) { throw new BusinessException("Password must be atleast 6 characters in length."); } var passwordComponent = new PasswordComponent(); var salt = passwordComponent.GetCryptographicSalt(); var user = new User { UserName = email, Password = passwordComponent.Hash(password, salt), PasswordSalt = salt, Email = email }; ValidateObject(user); context.Add(user); context.Commit(); return(user); }
protected virtual void RestoreViewModel([NotNull] Type viewModelType, [NotNull] IDataContext viewModelState, [NotNull] NSObject item, [NotNull] NSCoder coder, [NotNull] IDataContext context) { context = context.ToNonReadOnly(); context.AddOrUpdate(InitializationConstants.ViewModelType, viewModelType); if (item is IModalView) { context.Add(DynamicViewModelWindowPresenter.RestoredViewConstant, item); context.Add(DynamicViewModelWindowPresenter.IsOpenViewConstant, true); } var viewModel = _viewModelProvider.RestoreViewModel(viewModelState, context, false); _viewManager.InitializeViewAsync(viewModel, item, context).WithTaskExceptionHandler(this); _viewModelPresenter.Restore(viewModel, context); }
public async Task <IActionResult> Create([FromBody] NewAdminDto input) { if (input.Code != config.AdministratorRegistrationCode) { Response.Headers[Constants.InternalResponseCodeHeader] = InvalidCodeCode; return(BadRequest()); } if (context.Set <Administrator>().Any(a => a.Login == input.Login)) { Response.Headers[Constants.InternalResponseCodeHeader] = LoginDuplicationCode; return(BadRequest()); } Administrator a = null; using (context) { a = mapper.Map <Administrator>(input); a.Role = Core.Enums.Role.Admin; a.PasswordHash = new PasswordHash(input.Password).ToBase64(); a = context.Add(a); await context.SaveChangesAsync(); } return(Ok(tokenService.CreateTokenObject(a))); }
public bool Add(Product item) { bool result = productsDataContext.Add(item); ChangeInCollection?.Invoke(); return(result); }
/// <summary> /// Create a new web by specified web template. /// </summary> /// <param name="template">The web template object.</param> /// <param name="dbContext">The data context object.</param> /// <param name="name">The new web name.</param> /// <param name="owner">The new web owner name.</param> /// <returns>A new web instance created from template.</returns> public static Web Install(this WebElement template, IDataContext dbContext, string name, string owner) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } var thisWeb = dbContext.Find <Web>(w => w.Name.Equals(name, StringComparison.OrdinalIgnoreCase)); if (thisWeb == null) { thisWeb = new Web() { Name = name, Owner = string.IsNullOrEmpty(owner) ? name : owner, Created = DateTime.UtcNow, MostOnlined = DateTime.UtcNow, MostOnlineUserCount = 1, IsEnabled = true }; //thisWeb.Popuplate(template); thisWeb = dbContext.Add(thisWeb); dbContext.SaveChanges(); } foreach (var wpTmpl in template.Pages) { wpTmpl.Install(dbContext, thisWeb); } return(thisWeb); }
public virtual void Handle(TCommand command) { TModel model = CreateModel(command); _context.Add(model); _context.SaveChanges(); }
public Operation <Domain> Add <Domain>(Domain d) where Domain : class => Operation.Try(() => { _context.Add(d); _context.CommitChanges(); return(d); });
/// <summary> /// Creates a series of instances of <see cref="IDataBinding" />. /// </summary> /// <param name="target">The specified binding target.</param> /// <param name="bindingExpression">The specified binding expression.</param> /// <param name="sources">The specified sources, if any.</param> /// <returns>An instance of <see cref="IDataBinding" />.</returns> public IList <IDataBinding> CreateBindingsFromString(object target, string bindingExpression, IList <object> sources = null) { Should.NotBeNull(target, "target"); Should.NotBeNullOrWhitespace(bindingExpression, "bindingExpression"); try { IList <IDataContext> parserResult = Parser.Parse(bindingExpression, (sources == null || sources.Count == 0) ? DataContext.Empty : new DataContext(1) { { BindingBuilderConstants.RawSources, sources } }); var result = new IDataBinding[parserResult.Count]; for (int index = 0; index < parserResult.Count; index++) { IDataContext dataContext = parserResult[index]; dataContext.Add(BindingBuilderConstants.Target, target); result[index] = BuildBinding(dataContext); } return(result); } catch (Exception exception) { return(new[] { CreateInvalidDataBinding(new InvalidOperationException(exception.Message, exception)) }); } }
public int SaveProjectStatus(ProjectStatus projectStatus, int weekId, string userName) { if (projectStatus != null) { var dbProjectStatus = context.Query <ProjectStatus>() .Where(ps => ps.WeekId == weekId && ps.ProjectId == projectStatus.ProjectId).FirstOrDefault(); if (dbProjectStatus != null) { dbProjectStatus.ModifiedBy = userName; dbProjectStatus.ModifiedDate = DateTime.Now; dbProjectStatus.WeekId = weekId; dbProjectStatus.StatusId = projectStatus.StatusId; dbProjectStatus.ProjectSummary = projectStatus.ProjectSummary; context.Update(dbProjectStatus); } else { projectStatus.CreatedBy = userName; projectStatus.CreatedDate = DateTime.Now; projectStatus.ModifiedBy = userName; projectStatus.ModifiedDate = DateTime.Now; projectStatus.WeekId = weekId; context.Add(projectStatus); } } return(projectStatus.ProjectId); }
/// <summary> /// Create a new web by specified web template. /// </summary> /// <param name="template">The web template object.</param> /// <param name="dbContext">The data context object.</param> /// <param name="name">The new web name.</param> /// <param name="owner">The new web owner name.</param> /// <returns>A new web instance created from template.</returns> public static Web Install(this WebElement template, IDataContext dbContext, string name, string owner) { if (string.IsNullOrEmpty(name)) throw new ArgumentNullException("name"); var thisWeb = dbContext.Find<Web>(w => w.Name.Equals(name, StringComparison.OrdinalIgnoreCase)); if (thisWeb == null) { thisWeb = new Web() { Name = name, Owner = string.IsNullOrEmpty(owner) ? name : owner, Created = DateTime.UtcNow, MostOnlined = DateTime.UtcNow, MostOnlineUserCount = 1, IsEnabled = true }; //thisWeb.Popuplate(template); thisWeb = dbContext.Add(thisWeb); dbContext.SaveChanges(); } foreach (var wpTmpl in template.Pages) wpTmpl.Install(dbContext, thisWeb); return thisWeb; }
public void EnumerableTest() { const string st = "test"; IDataContext context = Create(); context.Add(InitializationConstants.ObservationMode, ObservationMode.Both); context.Count.ShouldEqual(1); context.Add(InitializationConstants.ViewModelBindingName, st); context.Count.ShouldEqual(2); var dictionary = context.ToList().ToDictionary(constantValue => constantValue.DataConstant, value => value.Value); dictionary.Count.ShouldEqual(2); dictionary[InitializationConstants.ObservationMode].ShouldEqual(ObservationMode.Both); dictionary[InitializationConstants.ViewModelBindingName].ShouldEqual(st); }
public void AddGetTryGetTest() { const string st = "test"; IDataContext context = Create(); context.Add(InitializationConstants.ObservationMode, ObservationMode.Both); context.Count.ShouldEqual(1); context.Add(InitializationConstants.ViewModelBindingName, st); context.Count.ShouldEqual(2); ObservationMode data; context.TryGetData(InitializationConstants.ObservationMode, out data).ShouldBeTrue(); data.ShouldEqual(ObservationMode.Both); context.GetData(InitializationConstants.ViewModelBindingName).ShouldEqual(st); }
protected virtual IBindingBuilder CreateBuilderInternal([NotNull] IDataContext context) { if (!context.Contains(BindingBuilderConstants.BuildDelegate)) { context.Add(BindingBuilderConstants.BuildDelegate, _buildDelegate); } return(new BindingBuilder(context)); }
public void Add(Product item) { Task.Run(() => { productsDataContext.Add(item); ChangeInCollection?.Invoke(); }); }
public static void BindJson(IDataContext context, JToken data) { if (data != null) { context.Add("body", data); if (data is JObject) { foreach (JProperty property in data) { if (property.Value != null) { context.Add(property.Name, property); } } } } }
protected virtual void RestoreViewModel([NotNull] Type viewModelType, [NotNull] IDataContext viewModelState, [NotNull] NSObject item, [NotNull] NSCoder coder, [NotNull] IDataContext context) { context = context.ToNonReadOnly(); context.AddOrUpdate(InitializationConstants.ViewModelType, viewModelType); if (item is IModalView) { context.Add(WindowPresenterConstants.RestoredView, item); context.Add(WindowPresenterConstants.IsViewOpened, true); } var viewModel = _viewModelProvider.RestoreViewModel(viewModelState, context, true); context.AddOrUpdate(NavigationConstants.ViewModel, viewModel); _viewManager.InitializeViewAsync(viewModel, item, context); _viewModelPresenter.Restore(context); }
public async Task <IActionResult> Post([FromBody] AddProductModel model) { var dataModel = model.ToDataModel(); await _dataContext.Add(dataModel, User.Identity); var uri = $"api/products/{dataModel.Id}"; return(Created(uri, dataModel)); }
public IBindingBuilder CreateBuilder(IDataContext context = null) { context = context.ToNonReadOnly(); if (!context.Contains(BindingBuilderConstants.BuildDelegate)) { context.Add(BindingBuilderConstants.BuildDelegate, _buildDelegate); } return(new BindingBuilder(context)); }
private void CreateParameter(IDataContext context, HttpRequest request, string name, string filename, string contentType , System.IO.MemoryStream stream) { if (string.IsNullOrEmpty(filename)) { string value = Encoding.UTF8.GetString(stream.GetBuffer(), 0, (int)stream.Length - 2); context.Add(name, value); } else { PostFile postFile = new PostFile(); stream.Position = 0; stream.SetLength(stream.Length - 2); postFile.Data = stream; postFile.FileName = filename; context.Add(name, postFile); request.Files.Add(postFile); } }
/// <summary> /// Adds the data constant value. /// </summary> public void Add <T>(DataConstant <T> data, T value) { try { _internalContext.Add(data, value); } catch (ArgumentException) { throw BindingExceptionManager.DuplicateDataConstant(data); } }
public async Task Create([FromBody] Income income) { var existingIncome = _context.Query <Income>().FirstOrDefault(i => i.Id == income.Id); if (existingIncome is null) { existingIncome = _context.Add(income); } await _context.Save(); }
private void btnNew_Click(object sender, EventArgs e) { IList<TakmicarskaKategorija> dodeljeneKategorije = getDodeljeneKategorije(); if (dodeljeneKategorije.Count == kategorijeCount) { MessageDialogs.showMessage( "Vec su odredjeni rasporedi sudija za sve kategorije.", this.Text); return; } string msg = "Izaberite kategorije za koje vazi raspored sudija"; DialogResult dlgResult = DialogResult.None; SelectKategorijaForm form = null; try { form = new SelectKategorijaForm(takmicenje.Id, dodeljeneKategorije, false, msg); dlgResult = form.ShowDialog(); } catch (InfrastructureException ex) { MessageDialogs.showError(ex.Message, this.Text); return; } if (dlgResult != DialogResult.OK || form.SelektovaneKategorije.Count == 0) return; RasporedSudija newRaspored = null; bool added = false; try { DataAccessProviderFactory factory = new DataAccessProviderFactory(); dataContext = factory.GetDataContext(); dataContext.BeginTransaction(); newRaspored = new RasporedSudija(form.SelektovaneKategorije, deoTakKod, takmicenje); dataContext.Add(newRaspored); dataContext.Commit(); added = true; } catch (Exception ex) { if (dataContext != null && dataContext.IsInTransaction) dataContext.Rollback(); MessageDialogs.showMessage( Strings.getFullDatabaseAccessExceptionMessage(ex), this.Text); } finally { if (dataContext != null) dataContext.Dispose(); dataContext = null; } if (!added) { Close(); return; } rasporedi.Add(newRaspored); tabOpened.Add(false); createTab(newRaspored); if (tabControl1.SelectedIndex != tabControl1.TabPages.Count - 1) tabControl1.SelectedIndex = tabControl1.TabPages.Count - 1; else onSelectedIndexChanged(); }
public virtual void Start(IDataContext context = null) { Initialize(); context = context.ToNonReadOnly(); if (!context.Contains(NavigationConstants.IsDialog)) context.Add(NavigationConstants.IsDialog, false); var app = MvvmApplication.Current; var viewModelType = app.GetStartViewModelType(); var mappingProvider = app.IocContainer.Get<IViewMappingProvider>(); IViewMappingItem mapping = mappingProvider.FindMappingForViewModel(viewModelType, context.GetData(NavigationConstants.ViewName), true); if (typeof(Page).IsAssignableFrom(mapping.ViewType)) { _rootWindow = CreateNavigationWindow(); var service = CreateNavigationService(_rootWindow); app.IocContainer.BindToConstant(service); } app.IocContainer.Get<IViewModelPresenter>().DynamicPresenters.Add(this); app.Start(context); }
public IBindingBuilder CreateBuilder(IDataContext context = null) { context = context.ToNonReadOnly(); if (!context.Contains(BindingBuilderConstants.BuildDelegate)) context.Add(BindingBuilderConstants.BuildDelegate, _buildDelegate); return new BindingBuilder(context); }
private void addCmd() { NacinIzboraGimnasticaraForm form2 = new NacinIzboraGimnasticaraForm(); if (form2.ShowDialog() != DialogResult.OK) return; List<GimnasticarUcesnik> selGimnasticari = new List<GimnasticarUcesnik>(); DialogResult dlgResult = DialogResult.None; SelectGimnasticariPrethTakmForm form3 = null; SelectGimnasticarForm form = null; if (form2.IzPrethodnogTakmicenja) { try { form3 = new SelectGimnasticariPrethTakmForm(ActiveKategorija.Gimnastika, false); dlgResult = form3.ShowDialog(); } catch (InfrastructureException ex) { MessageDialogs.showError(ex.Message, this.Text); } if (dlgResult != DialogResult.OK || form3.SelectedGimnasticari.Count == 0) return; } else { try { form = new SelectGimnasticarForm(ActiveKategorija.Gimnastika); dlgResult = form.ShowDialog(); } catch (InfrastructureException ex) { MessageDialogs.showError(ex.Message, this.Text); } if (dlgResult != DialogResult.OK || form.SelectedEntities.Count == 0) return; } bool added = false; List<GimnasticarUcesnik> okGimnasticari = new List<GimnasticarUcesnik>(); List<GimnasticarUcesnik> illegalGimnasticari = new List<GimnasticarUcesnik>(); try { DataAccessProviderFactory factory = new DataAccessProviderFactory(); dataContext = factory.GetDataContext(); dataContext.BeginTransaction(); if (form2.IzPrethodnogTakmicenja) { foreach (GimnasticarUcesnik g in form3.SelectedGimnasticari) { selGimnasticari.Add(createGimnasticarUcesnik( g, ActiveKategorija)); } } else { foreach (Gimnasticar g in form.SelectedEntities) { selGimnasticari.Add(createGimnasticarUcesnik( g, ActiveKategorija)); } } foreach (GimnasticarUcesnik g in selGimnasticari) { //GimnasticarUcesnik gimnasticar = createGimnasticarUcesnik( // g, ActiveKategorija); if (canAddGimnasticar(g/*imnasticar*/, ActiveKategorija)) okGimnasticari.Add(g/*imnasticar*/); else illegalGimnasticari.Add(g); } foreach (GimnasticarUcesnik g in okGimnasticari) dataContext.Add(g); dataContext.Commit(); added = true; } catch (Exception ex) { if (dataContext != null && dataContext.IsInTransaction) dataContext.Rollback(); MessageDialogs.showMessage( Strings.getFullDatabaseAccessExceptionMessage(ex), this.Text); } finally { if (dataContext != null) dataContext.Dispose(); dataContext = null; } if (!added) { Close(); return; } if (okGimnasticari.Count > 0) { List<GimnasticarUcesnik> activeGimnasticari = gimnasticari[tabControl1.SelectedIndex]; foreach (GimnasticarUcesnik g in okGimnasticari) { activeGimnasticari.Add(g); } setGimnasticari(activeGimnasticari); // NOTE: Ako je DataGridViewUserControl sortiran, tada metod setItems // (koga poziva metod setGimnasticari) osvezava prikaz (poziva // refreshItems). Ako nije sortiran, potrebno je eksplicitno osveziti // prikaz // Dodatni razlog zasto je potrebno osveziti prikaz je cinjenica da // se metod setItems poziva sa parametrom tipa List, a u tom slucaju // DataGridViewUserControl ne kreira novu listu za DataSource i nece // automatski osveziti prikaz. if (!getActiveDataGridViewUserControl().isSorted()) getActiveDataGridViewUserControl().refreshItems(); getActiveDataGridViewUserControl().setSelectedItem<GimnasticarUcesnik> (okGimnasticari[okGimnasticari.Count - 1]); updateGimnasticariCount(); } if (illegalGimnasticari.Count > 0) { string msg = "Sledeci gimnasticari vec postoje medju " + "prijavljenim gimansticarima: \n\n"; msg += StringUtil.getListString(illegalGimnasticari.ToArray()); MessageDialogs.showMessage(msg, this.Text); } }
public virtual void Start(IDataContext context = null) { Initialize(); context = context.ToNonReadOnly(); if (!context.Contains(NavigationConstants.IsDialog)) context.Add(NavigationConstants.IsDialog, false); var app = MvvmApplication.Current; app.IocContainer.Get<IViewModelPresenter>().DynamicPresenters.Add(this); app.Start(context); }
private static void SetAttributeValue(View view, Context context, IAttributeSet attrs, int[] groupId, int requiredAttributeId, string attachedMemberName, IDataContext dataContext, DataConstant<int> constant) { int? value = ReadAttributeValueId(context, attrs, groupId, requiredAttributeId); if (!value.HasValue) return; dataContext.Add(constant, value.Value); IBindingMemberInfo member = BindingServiceProvider .MemberProvider .GetBindingMember(view.GetType(), attachedMemberName, false, false); if (member != null) member.SetSingleValue(view, value); }