예제 #1
0
 public void AddTabsForCurrentRole(int roleId)
 {
     context.Tabs.Add(new Tab {
         Name = "Главная", IsChecked = true, /*IsSelected = true,*/ RoleId = roleId
     });
     context.Tabs.Add(new Tab {
         Name = "Файл", IsChecked = true, /*IsSelected = false,*/ RoleId = roleId
     });
     context.Tabs.Add(new Tab {
         Name = "Поля этикетки (Конфигурации)", IsChecked = true, /*IsSelected = false,*/ RoleId = roleId
     });
     context.Tabs.Add(new Tab {
         Name = "Цвет бейджа (Конфигурации)", IsChecked = true, /*IsSelected = false, */ RoleId = roleId
     });
     context.Tabs.Add(new Tab {
         Name = "Рабочий стол (Конфигурации)", IsChecked = true, /*IsSelected = false, */ RoleId = roleId
     });
     context.Tabs.Add(new Tab {
         Name = "Отчёты (Конфигурации)", IsChecked = true, /*IsSelected = false,*/ RoleId = roleId
     });
     context.Tabs.Add(new Tab {
         Name = "Регистрация (Администрирование)", IsChecked = true, /* IsSelected = false,*/ RoleId = roleId
     });
     context.Tabs.Add(new Tab {
         Name = "Авторизация (Администрирование)", IsChecked = true, /* IsSelected = false,*/ RoleId = roleId
     });
     context.Tabs.Add(new Tab {
         Name = "Управление доступом (Администрирование)", IsChecked = true, /* IsSelected = false,*/ RoleId = roleId
     });
     context.Tabs.Add(new Tab {
         Name = "Режим работы (Сеть)", IsChecked = true, /*IsSelected = false,*/ RoleId = roleId
     });
     context.SaveChanges();
 }
예제 #2
0
 public DisplaySetting AddOrUpdateDisplaySetting(DisplaySetting displaySetting)
 {
     context.DisplaySettings.AddOrUpdate(displaySetting);
     context.SaveChanges();
     return(context.DisplaySettings.Where(s =>
                                          s.Name == displaySetting.Name &&
                                          s.Intendant == displaySetting.Intendant).FirstOrDefault());
 }
예제 #3
0
 public PrintSetting AddOrUpdatePrintSetting(PrintSetting printSetting)
 {
     context.PrintSettings.AddOrUpdate(printSetting);
     context.SaveChanges();
     return(context.PrintSettings.Where(s =>
                                        s.Name == printSetting.Name &&
                                        s.IsSelected == printSetting.IsSelected).FirstOrDefault());
 }
예제 #4
0
 public User AddOrUpdateUser(User user)
 {
     if (context.Users.Where(s => s.Login == user.Login && s.Id == 0).Count() == 0)
     {
         context.Users.AddOrUpdate(user);
         context.SaveChanges();
     }
     return(context.Users.Where(s => s.Login == user.Login).FirstOrDefault());
 }
 public PrintStringSetting AddOrUpdatePrintStringSetting(PrintStringSetting printStringSetting)
 {
     context.PrintStringSettings.AddOrUpdate(printStringSetting);
     context.SaveChanges();
     return(context.PrintStringSettings.Where(p =>
                                              p.Id == printStringSetting.Id &&
                                              p.Name == printStringSetting.Name &&
                                              p.ToUpper == printStringSetting.ToUpper &&
                                              p.Visible == printStringSetting.Visible &&
                                              p.PrintSettingId == printStringSetting.PrintSettingId).FirstOrDefault());
 }
예제 #6
0
 public VisitorRepository(string file)
 {
     context = new EContext();
     if (!context.Database.Exists())
     {
         context.Database.Delete();
         context.SaveChanges();
         exelData = new ExelData(file);
         exelData.setDataToCollection(context.Visitors);
         context.SaveChanges();
     }
 }
예제 #7
0
        public Role AddOrUpdate(Role role)
        {
            bool needAddAtribute = role.Id == 0;

            context.Roles.AddOrUpdate(role);
            context.SaveChanges();
            if (needAddAtribute)
            {
                var roleId   = context.Roles.Where(r => r.Name == role.Name).FirstOrDefault().Id;
                var tabs     = new TabRepository();
                var commands = new CommandRepository();
                tabs.AddTabsForCurrentRole(roleId);
                commands.AddCommandForCurrentRole(roleId);
            }
            return(context.Roles.Where(r => r.Name == role.Name).FirstOrDefault());
        }
예제 #8
0
        public async Task <bool> DeleteById(string id)
        {
            try
            {
                var vehicle = await _context.Vehicles.Where(v => v.Id == id).FirstOrDefaultAsync();

                if (vehicle == null)
                {
                    throw new KeyNotFoundException("vehicle not found");
                }

                _context.Vehicles.Remove(vehicle);
                int affected = _context.SaveChanges();
                if (affected <= 0)
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                //Exception should be logged somewhere
                throw;
            }

            return(true);
        }
예제 #9
0
        public static void Initialize(EContext context)
        {
            context.Database.EnsureCreated();

            //already db has been seeded before, no need to continue
            if (context.Vehicles.Any())
            {
                return;
            }

            //seed db
            var vehicles = new Vehicle[]
            {
                new Vehicle {
                    Year = 1980, Make = "Explorer", Model = "Ford"
                },
                new Vehicle {
                    Year = 2005, Make = "Taho", Model = "Chevy"
                },
                new Vehicle {
                    Year = 2010, Make = "Edge", Model = "Ford"
                },
                new Vehicle {
                    Year = 2015, Make = "Evoque", Model = "Land Rover"
                }
            };


            foreach (var vehicle in vehicles)
            {
                context.Vehicles.Add(vehicle);
            }

            context.SaveChanges();
        }
예제 #10
0
        public void importRepositoryFromFileWithId(string fileName, Action <Progress_Bar> progressChanged)
        {
            ExelData exelData = new ExelData(fileName, progressChanged);

            progress.Status   = "Delete old visitors";
            progress.Progress = 0;
            using (var ctx = new EContext())
            {
                int count      = 1;
                var collection = ctx.Visitors.ToList();
                var size       = collection.Count() + 1;
                foreach (var u in collection)
                {
                    progress.Progress = (int)(count * 100 / size);
                    progressChanged(progress);
                    ctx.Visitors.Remove(u);
                    count++;
                }
                ctx.SaveChanges();

                var dat = new List <Visitor>();
                exelData.importVisitorsToCollectionWithId(dat, progressChanged);
                progress.Status   = "Add new data to database";
                progress.Progress = 0;
                int co = 1;
                var sd = dat.Count() + 1;
                foreach (var d in dat)
                {
                    const string InsertQuery = @"SET IDENTITY_INSERT dbo.Visitors ON;
                                                 INSERT INTO Visitors(Id, Column1, Column2,
                                                 Column3, Column4, Column5, Column6, Column7, 
                                                 Column8, Column9, Column10, Column11, Column12,
                                                 Column13, Column14, Column15, CurrentStatus) 
                                                 VALUES({0},{1},{2},{3},{4},{5},{6},{7},
                                                 {8},{9},{10},{11},{12},{13},{14},{15},{16}); 
                                                 SET IDENTITY_INSERT dbo.Visitors OFF;";
                    context.Database.ExecuteSqlCommand(InsertQuery, d.Id, d.Column1,
                                                       d.Column2, d.Column3, d.Column4, d.Column5, d.Column6, d.Column7,
                                                       d.Column8, d.Column9, d.Column10, d.Column11, d.Column12,
                                                       d.Column13, d.Column14, d.Column15, d.CurrentStatus);
                    context.SaveChanges();
                    progress.Progress = (int)(co * 100 / sd);
                    progressChanged(progress);
                    co++;
                }
            }
            progress.Status   = "Add new data to collection";
            progress.Progress = 0;
            int c   = 1;
            var col = context.Visitors.ToList();
            var s   = col.Count() + 1;

            foreach (var v in col)
            {
                progress.Progress = (int)(c * 100 / s);
                progressChanged(progress);
                AddOrUpdateVisitor(v);
                c++;
            }
        }
예제 #11
0
 public void SaveCategory(Category category)
 {
     using (var context = new EContext())
     {
         context.Categories.Add(category);
         context.SaveChanges();
     }
 }
 AddOrUpdateDSCollumnSetting(DSCollumnSetting dSCollumnSetting)
 {
     context.DSCollumnSettings.AddOrUpdate(dSCollumnSetting);
     context.SaveChanges();
     //if (context.DSCollumnSettings.Where(d=>
     //d.Name == dSCollumnSetting.Name&&
     //d.Visible == dSCollumnSetting.Visible&&
     //d.Width == dSCollumnSetting.Width).Count() == 0)
     //{
     //    context.DSCollumnSettings.AddOrUpdate(dSCollumnSetting);
     //    context.SaveChanges();
     //}
     return(context.DSCollumnSettings.Where(d =>
                                            d.Name == dSCollumnSetting.Name &&
                                            d.Visible == dSCollumnSetting.Visible &&
                                            d.Width == dSCollumnSetting.Width).FirstOrDefault());
 }
예제 #13
0
 public void UpdateCategory(Category category)
 {
     using (var context = new EContext())
     {
         context.Entry(category).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
예제 #14
0
 public void UpdateProduct(Product product)
 {
     using (var context = new EContext())
     {
         context.Entry(product).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
예제 #15
0
 public void DeleteProduct(int id)
 {
     using (var context = new EContext())
     {
         var product = context.Products.Find(id);
         context.Products.Remove(product);
         context.SaveChanges();
     }
 }
예제 #16
0
 public void DeleteOrder(int id)
 {
     using (var context = new EContext())
     {
         var order = context.Orders.Find(id);
         context.Orders.Remove(order);
         context.SaveChanges();
     }
 }
예제 #17
0
        public UserInRole AddOrUpdateUserInRole(UserInRole userInRole)
        {
            var checkUserInRole = context.UserInRoles.Where(ur =>
                                                            ur.RoleId == userInRole.RoleId &&
                                                            ur.UserId == userInRole.UserId).FirstOrDefault();

            if (checkUserInRole == null)
            {
                context.UserInRoles.AddOrUpdate(userInRole);
                context.SaveChanges();
                return(context.UserInRoles.Where(ur =>
                                                 ur.RoleId == userInRole.RoleId &&
                                                 ur.UserId == userInRole.UserId).FirstOrDefault());
            }
            else
            {
                return(checkUserInRole);
            }
        }
예제 #18
0
        public void SaveProduct(Product product)
        {
            using (var context = new EContext())
            {
                context.Entry(product.Category).State = System.Data.Entity.EntityState.Unchanged;

                context.Products.Add(product);
                context.SaveChanges();
            }
        }
예제 #19
0
        public int SaveOrder(Order order)
        {
            using (var context = new EContext())
            {
                context.Orders.Add(order);
                return(context.SaveChanges());

                //context.Orders.Add(order);
                //context.SaveChanges();
            }
        }
예제 #20
0
        public void DeleteCategory(int id)
        {
            using (var context = new EContext())
            {
                var category = context.Categories.Where(x => x.Id == id).Include(x => x.Products).FirstOrDefault();

                context.Products.RemoveRange(category.Products);//first delete product of this category
                context.Categories.Remove(category);
                context.SaveChanges();
            }
        }
예제 #21
0
        public IEnumerable <Visitor> AddDataToRepositoryFromFile(string fileName)
        {
            ExelData exelData = new ExelData(fileName);

            exelData.setDataToCollection(context.Visitors);
            context.SaveChanges();
            var v = context.Visitors.ToList();

            return(v);
        }
예제 #22
0
 public void AddCommandForCurrentRole(int roleId)
 {
     context.Commands.Add(new Command {
         Name = "AddUser", IsChecked = true, RoleId = roleId
     });
     context.Commands.Add(new Command {
         Name = "DelUser", IsChecked = true, RoleId = roleId
     });
     context.Commands.Add(new Command {
         Name = "AddRoles", IsChecked = true, RoleId = roleId
     });
     context.Commands.Add(new Command {
         Name = "DelRoles", IsChecked = true, RoleId = roleId
     });
     context.Commands.Add(new Command {
         Name = "SaveChanges", IsChecked = true, RoleId = roleId
     });
     context.Commands.Add(new Command {
         Name = "LoadFile", IsChecked = true, RoleId = roleId
     });
     context.SaveChanges();
 }
예제 #23
0
        public bool UpdateOrderStatus(int Id, string status)
        {
            using (var context = new EContext())
            {
                var order = context.Orders.Find(Id);

                order.Status = status;

                context.Entry(order).State = EntityState.Modified;

                return(context.SaveChanges() > 0);
            }
        }
예제 #24
0
 public Visitor AddOrUpdateVisitor(Visitor visitor)
 {
     if (context.Visitors.Where(s => s.Column1 == visitor.Column1 &&
                                s.Column2 == visitor.Column2 &&
                                s.Column3 == visitor.Column3 &&
                                s.Column4 == visitor.Column4 &&
                                s.Column5 == visitor.Column5 &&
                                s.Column6 == visitor.Column6 &&
                                s.Column7 == visitor.Column7 &&
                                s.Column8 == visitor.Column8 &&
                                s.Column9 == visitor.Column9 &&
                                s.Column10 == visitor.Column10 &&
                                s.Column11 == visitor.Column11 &&
                                s.Column12 == visitor.Column12 &&
                                s.Column13 == visitor.Column13 &&
                                s.Column14 == visitor.Column14 &&
                                s.Column15 == visitor.Column15).Count() == 0)
     {
         context.Visitors.AddOrUpdate(visitor);
         context.SaveChanges();
     }
     return(context.Visitors.Where(s => s.Column1 == visitor.Column1 &&
                                   s.Column2 == visitor.Column2 &&
                                   s.Column3 == visitor.Column3 &&
                                   s.Column4 == visitor.Column4 &&
                                   s.Column5 == visitor.Column5 &&
                                   s.Column6 == visitor.Column6 &&
                                   s.Column7 == visitor.Column7 &&
                                   s.Column8 == visitor.Column8 &&
                                   s.Column9 == visitor.Column9 &&
                                   s.Column10 == visitor.Column10 &&
                                   s.Column11 == visitor.Column11 &&
                                   s.Column12 == visitor.Column12 &&
                                   s.Column13 == visitor.Column13 &&
                                   s.Column14 == visitor.Column14 &&
                                   s.Column15 == visitor.Column15).FirstOrDefault());
 }
예제 #25
0
        public void importStatusRepositoryFromFileWithId(string fileName, Action <Progress_Bar> progressChanged)
        {
            ExelData exelData = new ExelData(fileName, progressChanged);

            progress.Status   = "Delete old statuses";
            progress.Progress = 0;
            using (var ctx = new EContext())
            {
                int count      = 1;
                var collection = ctx.Statuses.ToList();
                var size       = collection.Count() + 1;
                foreach (var stat in collection)
                {
                    progress.Progress = (int)(count * 100 / size);
                    progressChanged(progress);
                    ctx.Statuses.Remove(stat);
                    count++;
                }
                ctx.SaveChanges();
                var dat = new List <Status>();
                exelData.importSatausToCollectionWithId(dat, progressChanged);
                progress.Status   = "Add new data to database";
                progress.Progress = 0;
                int co = 1;
                var sd = dat.Count() + 1;
                foreach (var d in dat)
                {
                    const string InsertQuery = @"SET IDENTITY_INSERT dbo.Status ON;
                                                 INSERT INTO Status(Id, Name, ActionTime,
                                                 UserId, VisitorId) 
                                                 VALUES({0},{1},{2},{3},{4}); 
                                                 SET IDENTITY_INSERT dbo.Status OFF;";
                    try
                    {
                        context.Database.ExecuteSqlCommand(InsertQuery, d.Id, d.Name,
                                                           d.ActionTime, d.UserId, d.VisitorId);
                        context.SaveChanges();
                    }
                    catch { }
                    progress.Progress = (int)(co * 100 / sd);
                    progressChanged(progress);
                    co++;
                }
            }
        }
예제 #26
0
        public bool Eliminar(Expression <Func <T, bool> > predicate)
        {
            bool blResultado = false;

            using (EContext context = new EContext())
            {
                try
                {
                    var entities = context.Set <T>().Where(predicate).ToList();
                    entities.ForEach(x => context.Entry(x).State = EntityState.Deleted);
                    context.SaveChanges();
                    blResultado = true;
                }
                catch (Exception ex)
                {
                    blResultado = false;
                    throw new Exception(ex.Message);
                }
            }
            return(blResultado);
        }
예제 #27
0
        public bool Eliminar(T entity)
        {
            bool blResultado = false;

            using (EContext context = new EContext())
            {
                try
                {
                    context.Entry(entity).State = EntityState.Deleted;
                    context.SaveChanges();

                    blResultado = true;
                }
                catch (Exception ex)
                {
                    blResultado = false;
                    throw new Exception(ex.Message);
                }
            }
            return(blResultado);
        }
예제 #28
0
        public bool Crear(T entity)
        {
            bool blResultado = false;

            using (EContext context = new EContext())
            {
                try
                {
                    context.Set <T>().Add(entity);
                    context.SaveChanges();

                    blResultado = true;
                }
                catch (Exception ex)
                {
                    blResultado = false;
                    throw new Exception(ex.Message);
                }
            }
            return(blResultado);
        }
예제 #29
0
        public void initRepositoryFromFile(string fileName, Action <Progress_Bar> progressChanged)
        {
            ExelData exelData = new ExelData(fileName, progressChanged);

            progress.Status   = "Delete old visitors";
            progress.Progress = 0;
            using (var ctx = new EContext())
            {
                int count      = 1;
                var collection = ctx.Visitors.ToList();
                var size       = collection.Count() + 1;
                foreach (var u in collection)
                {
                    progress.Progress = (int)(count * 100 / size);
                    progressChanged(progress);
                    ctx.Visitors.Remove(u);
                    count++;
                }
                ctx.SaveChanges();
            }
            exelData.setDataToCollection(context.Visitors, progressChanged);
            context.SaveChanges();
            progress.Status   = "Add new data to collection";
            progress.Progress = 0;
            int c   = 1;
            var col = context.Visitors;
            var s   = col.Count() + 1;

            foreach (var v in col)
            {
                progress.Progress = (int)(c * 100 / s);
                progressChanged(progress);
                //   visitorCollection.Add(v);
                AddOrUpdateVisitor(v);
                c++;
            }
        }
예제 #30
0
 public void RemoveStatus(Status status)
 {
     context.Statuses.Remove(status);
     context.SaveChanges();
 }