public virtual dynamic Insert(T entity)
        {
            dynamic obj = dbSet.Add(entity);

            this._unitOfWork.Db.SaveChanges();
            return(obj);
        }
Exemplo n.º 2
0
        private bool Register(string ClientID, string emailAddress, string Password)
        {
            if (LogEvent != null)
            {
                LogEvent("Registering User");
            }
            using (var db = new DamoclesEntities())
            {
                System.Data.Entity.DbSet <User> users = db.Users;

                var eu = Users.CreateUser(ClientID, emailAddress, Password);

                users.Add(eu);

                int rows = db.SaveChanges();
                if (rows < 1)
                {
                    if (LogEvent != null)
                    {
                        LogEvent("Failed to Add user: " + emailAddress);
                    }
                    return(false);
                }
                else
                {
                    login.UpdateLoginHistory(emailAddress);
                    return(true);
                }
            }
        }
Exemplo n.º 3
0
        public static void AddOrder(DTO.Order current_order, DTO.Customer current_customer)
        {
            PapaBobEntities db = new PapaBobEntities();

            System.Data.Entity.DbSet <Order> dbOrders = db.Orders;
            var dbCustomers = db.Customers;

            var new_order = new Persistence.Order();

            CreateNewOrder(current_order, out new_order);

            var  dbCustomersList         = db.Customers.ToList();
            bool check_if_customer_exits = CustomerRepository.CustomerExists(dbCustomersList, current_customer);

            if (!check_if_customer_exits)
            {
                var new_customer = new Customer();
                CustomerRepository.CreateNewCustomer(current_customer, out new_customer);
                new_order.customer_id     = new_customer.customer_id;
                new_customer.amount_owing = current_order.payment_type != DTO.Payment.Cash ? current_order.cost : 0;
                new_order.Customer        = new_customer;
                dbCustomers.Add(new_customer);
            }
            else
            {
                var existing_customer = dbCustomersList?.Find(p => p.phone_number == current_customer.phone_number);
                new_order.customer_id           = existing_customer.customer_id;
                existing_customer.amount_owing += current_order.payment_type != DTO.Payment.Cash ? current_order.cost : 0;
            }

            dbOrders.Add(new_order);
            db.SaveChanges();
        }
Exemplo n.º 4
0
        public int Save(Team entity)
        {
            var savedEntity = _set.Add(entity);

            _bundesligaContext.SaveChanges();
            return(savedEntity.Id);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Метод добавляет департамент.
 /// </summary>
 public bool AddDepartment(Department n)
 {
     dep_list.Add(new Department()
     {
         Name = n.Name
     });
     DBModel.entities.SaveChanges();
     return(true);
 }
Exemplo n.º 6
0
        /// <summary>
        /// 新增
        /// </summary>
        public void Create(BackendContext db, System.Data.Entity.DbSet dbSet)
        {
            if (this.InitDate == null)
            {
                this.InitDate = DateTime.Now;
            }

            this.Poster = System.Web.HttpContext.Current.User.Identity.Name;
            dbSet.Add(this);
            db.SaveChanges();
        }
Exemplo n.º 7
0
        public int Create(string name, int?idParent = null)
        {
            var newEntity = new Genres()
            {
                IdParent = idParent,
                Name     = name
            };

            genres.Add(newEntity);
            Save();
            return(newEntity.Id);
        }
Exemplo n.º 8
0
 /// <summary>
 /// Метод добавляет сотрудника.
 /// </summary>
 public bool AddEmployee(Employee n)
 {
     emp_list.Add(new Employee()
     {
         Name         = n.Name,
         Age          = n.Age,
         Salary       = n.Salary,
         DepartmentID = n.DepartmentID
     });
     DBModel.entities.SaveChanges();
     return(true);
 }
Exemplo n.º 9
0
        /// <summary>	Prepare asynchronous. </summary>
        ///
        /// <param name="context">				The submit context. </param>
        /// <param name="cancellationToken">	A cancellation token. </param>
        ///
        /// <returns>	A System.Threading.Tasks.Task. </returns>
        public async Task PrepareAsync(SubmitContext context, CancellationToken cancellationToken)
        {
            //Source query expression dynamically
            var dbContext = context.ApiContext.GetProperty <DynamicContext>(DynamicContext.cDbContextKey);

            if (dbContext != null)
            {
                foreach (var entry in context.ChangeSet.Entries.OfType <DataModificationEntry>())
                {
                    Type entityType = dbContext.GetModelType(entry.EntitySetName);
                    System.Data.Entity.DbSet set = dbContext.Set(entityType);

                    object entity = null;

                    if (entry.IsNew)
                    {
                        entity = set.Create();

                        SetValues(entity, entityType, entry.LocalValues);

                        set.Add(entity);
                    }
                    else if (entry.IsDelete)
                    {
                        entity = await FindEntity(context, entry, cancellationToken);

                        set.Remove(entity);
                    }
                    else if (entry.IsUpdate)
                    {
                        entity = await FindEntity(context, entry, cancellationToken);

                        DbEntityEntry dbEntry = dbContext.Entry(entity);
                        SetValues(dbEntry, entry, entityType);
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }

                    entry.Entity = entity;
                }
            }
            else if (this.InnerHandler != null)
            {
                await this.InnerHandler.PrepareAsync(context, cancellationToken);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
        public void Add(DAL.Classes.Models.User user)
        {
            ValidateContext();

            if (user == null)
            {
                throw new ArgumentNullException("entity cannot be null");
            }

            dbSet.Add(new EFExample.DataModel.User()
            {
                Alias = user.Alias
            });
        }
Exemplo n.º 11
0
 public bool addLeilao(Leilao leilao)
 {
     try
     {
         leilaoContext.Add(leilao);
         dataBase.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(false);
     }
 }
Exemplo n.º 12
0
 public bool addUsuario(Usuario usuario)
 {
     try
     {
         usuarioContext.Add(usuario);
         dataBase.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         throw new Exception("Não foi possivel inserir o usuario, erro: " + e.Message);
     }
 }
Exemplo n.º 13
0
        public Product Add(string name, decimal?cost, int?category)
        {
            //var newId = _products.Any() ? _products.Max(p => p.id) + 1 : 1;
            var newProduct = new Product
            {
                name     = name,
                cost     = cost,
                category = category
            };
            var product = _products.Add(newProduct);

            entities.SaveChanges();
            return(product);
        }
Exemplo n.º 14
0
 public bool addLance(Lance lance)
 {
     try
     {
         lanceContext.Add(lance);
         dataBase.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(false);
     }
 }
Exemplo n.º 15
0
 private void SeedAdminUser(DamoclesEntities db, System.Data.Entity.DbSet<User> usrs, User su, string em)
 {
     if (LogEvent != null) LogEvent("Seeding Admin User");
     su.emailAddress = em;
     su.UserPasswordHash = "097dfd905dfa0e078883b7afcf7e653dde569bb1ed2ce3384d9c9ed7b85741d6e8d1b1a356318805d3c8b31b36a9916936d005d8134fb015d0392cf75cd7fa24";
     su.RegisteredDate = DateTime.UtcNow;
     su.CountryId = 3;
     su.StateId = 2;
     su.JurisidictionId = 4;
     su.LanguagesId = 1;
     su.IsOnline = false;
     su.AccountStatusId = 3;
     //   su.LicenseNumber = license.GenerateTemporaryLicenseNumber(em);
     su.emailAddress = em;
     su.UserClientID = null;
     su.CurrentClientID = null;
     usrs.Add(su);
     db.SaveChanges();
 }
Exemplo n.º 16
0
        public FakeEFContext() : base()
        {
            Images   = new TestDbSet <Image>();
            Products = new TestDbSet <Product>();
            byte[] picture = { 1, 2, 3, 4 };

            for (int i = 1; i < 10; i++)
            {
                var image = new Image(picture, "png")
                {
                    Id = i
                };
                Images.Add(image);
                Products.Add(new Product("www.mydomain.com", i.ToString(), i, new HashSet <Image>()
                {
                    image
                }, Currencies.CurrencyValues[0])
                {
                    Id = i
                });
            }
        }
Exemplo n.º 17
0
 public void Add(Driver driver)
 {
     dbSet.Add(driver);
 }
Exemplo n.º 18
0
 public void Insert(T t)
 {
     dbSet.Add(t);
 }
 public TEntity Inserir(TEntity entity)
 {
     _context.Add(entity);
     ((ContextCestaBD)_unitOfWork).Entry(entity).State = System.Data.Entity.EntityState.Added;
     return(entity);
 }