Exemplo n.º 1
0
 public DeviceModelManager()
 {
     using (var ctx = new FiscalDbContext())
     {
         AllData = ctx.DeviceModels.ToList();
     }
 }
        private void LoginUser(object sender, RoutedEventArgs e)
        {
            string username = users.Text;
            string salt;

            using (var ctx = new FiscalDbContext())
            {
                salt = ctx.Set <Serviceman>().
                       Where(x => x.Name + " " + x.Surname == username).
                       Select(x => x.Salt).
                       FirstOrDefault();
            }

            var hashedPassword = SHA256Hasher(passwd.Password, salt);

            if (IsPasswordValid(username, hashedPassword))
            {
                using (var ctx = new FiscalDbContext())
                {
                    LoggedUser = ctx.Set <Serviceman>().
                                 Where(x => x.Name + " " + x.Surname == username).
                                 FirstOrDefault();
                }

                GoToMainWindow(username);
            }
            else
            {
                // WriteLoginFailedMessage();
            }
        }
 public RevenueManager()
 {
     using (var ctx = new FiscalDbContext())
     {
         AllData = ctx.Set <Revenue>().ToList();
     }
 }
Exemplo n.º 4
0
 public virtual void TestCleanup()
 {
     using (var db = new FiscalDbContext())
         if (db.Database.Exists())
         {
             db.Database.Delete();
         }
 }
        private ObservableCollection <Serviceman> GetUsersFromDB()
        {
            ObservableCollection <Serviceman> allServicemen;

            using (var ctx = new FiscalDbContext())
            {
                allServicemen = new ObservableCollection <Serviceman>(ctx.Set <Serviceman>().ToList());
            }

            return(allServicemen);
        }
Exemplo n.º 6
0
        public virtual void TestInitialize()
        {
            using (var db = new FiscalDbContext())
            {
                if (db.Database.Exists())
                {
                    db.Database.Delete();
                }

                db.Database.Create();
            }
        }
Exemplo n.º 7
0
 private void GetDataFromDB()
 {
     using (var ctx = new FiscalDbContext())
     {
         EntitySearcher.Collection = new ObservableCollection <Client>
                                     (
             ctx.Clients
             .Include("Revenue")
             .Include("Devices")
             .Include("Devices.Place")
                                     );
     }
 }
        private bool IsPasswordValid(string username, string hashpwd)
        {
            string hashtOfUser;

            using (var ctx = new FiscalDbContext())
            {
                hashtOfUser = ctx.Set <Serviceman>().
                              Where(x => x.Name + " " + x.Surname == username).
                              Select(x => x.Hash).
                              FirstOrDefault();
            }
            return(hashtOfUser == hashpwd);
        }
        public DeviceEditViewModel(Device dev)
        {
            StateManager = new StateManager();

            Entity = dev;

            using (var ctx = new FiscalDbContext())
            {
                Client = ctx.Clients.FirstOrDefault();
            }
            Entity.Client = Client;

            DeviceModel        = new DeviceModel();
            DeviceModelManager = new DeviceModelManager();

            ButtonText  = "Edytuj";
            WindowTitle = "Edytowanie urządzenia";
        }
        public override void OperateOnDatabase(Device entity)
        {
            using (var ctx = new FiscalDbContext())
            {
                Place oldPlace = ctx.Places.Include("Devices").FirstOrDefault(x => x.ID == entity.Place.ID);
                // Is old place different than new place
                if (!oldPlace.Equals(entity.Place))
                {
                    Place newPlace      = entity.Place;
                    Place NewPlaceExist = ctx.Places.FirstOrDefault(x => x.State == newPlace.State && x.City == newPlace.City && x.Street == newPlace.Street);
                    newPlace.Devices = null;
                    newPlace.ID      = 0;

                    if (NewPlaceExist == null)
                    {
                        Place z = ctx.Places.Add(newPlace);
                        entity.Place   = z;
                        entity.PlaceId = z.ID;
                    }
                    else
                    {
                        entity.Place   = NewPlaceExist;
                        entity.PlaceId = NewPlaceExist.ID;
                        ctx.Entry(ctx.Set <Place>().Find(entity.PlaceId)).CurrentValues.SetValues(entity.Place);
                    }

                    oldPlace = ctx.Places.FirstOrDefault(x => x.ID == oldPlace.ID);

                    if (oldPlace.Devices.Count == 0)
                    {
                        ctx.Places.Remove(oldPlace);
                    }
                }

                ctx.Entry(ctx.Set <Device>().Find(entity.ID)).CurrentValues.SetValues(entity);
                ctx.SaveChanges();
            }
        }
 public AddEditOperationViewModel(FiscalDbContext context)
 {
     Context = context;
 }