private void SignIn() { using (ScanSystemsContext db = new ScanSystemsContext()) { var user = db.Users.FirstOrDefault(x => x.Login == login && x.Password == password); if (user == null) { ShowMessage("Ошибка аутоидентификации!", "Некорректный логин или пароль!"); } else { user.DeviceSerialNumber = GetDeviceId(); db.Entry(user).State = EntityState.Modified; db.SaveChanges(); userId = user.Id; Login = ""; Password = ""; Navigation.PopAsync(animated); //Navigation.RemovePage(Navigation.PopAsync().Result); Navigation.PushAsync(new MenuView { BindingContext = this }, animated); } } }
private void Settings() { bool openLogin = false; bool isAdmin = false; using (ScanSystemsContext db = new ScanSystemsContext()) { var user = userId.HasValue ? db.Users.FirstOrDefault(x => x.Id == userId.Value) : null; if (user == null) { openLogin = true; userId = null; } else { isAdmin = user.IsAdmin; } } if (isAdmin) { Navigation.PushAsync(new SettingsView { BindingContext = new SettingsViewModel { Navigation = Navigation } }, animated); } else if (openLogin) { Navigation.PopToRootAsync(animated); } else { ShowMessage("Доступ запрещен!", $"У данного пользователя нет доступа{Environment.NewLine}к редактированию настроек!"); } }
public void Initialize(CodeType[] baseCodeType, Product product) { using (ScanSystemsContext db = new ScanSystemsContext()) { models.AddRange(InitializeModels(db.CodeTypes.ToList())); models.ForEach(x => x.FullPackage += FullPackage); child = models.First(x => x.Child == null); this.product = product; child.ProductId = product.Id; CurrentRegistratorModel = child; } }
public RegistrationResult Registration(string dataMatrix) { RegistrationResult result = RegistrationResult.Success; using (ScanSystemsContext db = new ScanSystemsContext()) { DMCode dm = db.DMCodes.FirstOrDefault(x => x.DataMatrix == dataMatrix && x.DMCodeStateId == 1); if (dm != null) { RegisterCode code = new RegisterCode { Id = Guid.NewGuid(), CodeTypeId = BaseCodeType.Id, CurrentCode = dm.Id }; dm.DMCodeStateId = BaseCodeType.DMCodeStateId; db.Entry(dm).State = EntityState.Modified; if (Child == null) { dm.ProductId = ProductId; db.RegisterCodes.Add(code); db.SaveChanges(); Codes.Add(code); } else { if (Child.Codes.Count > 0) { foreach (var rcode in Child.Codes) { rcode.ParentCode = dm.Id; db.Entry(rcode).State = EntityState.Modified; } db.RegisterCodes.Add(code); db.SaveChanges(); Child.Codes.Clear(); Codes.Add(code); } else { result = RegistrationResult.NoChildren; } } } else { result = RegistrationResult.CodeRegitered; } } return(result); }
protected override void Initialization() { RegisteredCodes = new ObservableCollection <RegisterCode>(); DetailsCommand = new Command(Details); using (ScanSystemsContext db = new ScanSystemsContext()) { db.RegisterCodes.ToList().ForEach((x) => { RegisteredCodes.Add(x); }); } }
protected override void Initialization() { ShownCommand = new Command(Shown); SignInCommand = new Command(SignIn); SignOutCommand = new Command(SignOut); ScanModeCommand = new Command(ScanMode); DataCommand = new Command(Data); SettingsCommand = new Command(Settings); if (!initialized) { using (ScanSystemsContext db = new ScanSystemsContext()) { db.Database.EnsureCreated(); db.SaveChanges(); } } base.Initialization(); }
private void SignOut() { using (ScanSystemsContext db = new ScanSystemsContext()) { if (userId.HasValue) { var user = db.Users.FirstOrDefault(x => x.Id == userId.Value); if (user != null) { user.DeviceSerialNumber = string.Empty; db.Entry(user).State = EntityState.Modified; db.SaveChanges(); } userId = null; } } userId = null; Navigation.PopToRootAsync(); Navigation.PushAsync(new LoginView { BindingContext = this }, animated); }
private void Shown() { bool signedIn = false; using (ScanSystemsContext db = new ScanSystemsContext()) { var user = db.Users.FirstOrDefault(x => x.DeviceSerialNumber == GetDeviceId()); if (user != null) { if (user.LastSignIn.AddDays(1) < DateTime.Now) { user.DeviceSerialNumber = null; } else { user.LastSignIn = DateTime.Now; signedIn = true; } db.Entry(user).State = EntityState.Modified; } db.SaveChanges(); } if (signedIn) { Navigation.PopToRootAsync(); Navigation.PushAsync(new MenuView { BindingContext = this }, animated); } else { Navigation.PopToRootAsync(); Navigation.PushAsync(new LoginView { BindingContext = this }, animated); } }
static void Main(string[] args) { string[] codes = GetCodes(); Product product = null; using (ScanSystemsContext db = new ScanSystemsContext()) { db.Database.EnsureCreated(); product = db.Products.FirstOrDefault(); } Registrator reg = new Registrator(); //reg.Initialize(new CodeType() { Id = 3 }, product); foreach (var dm in codes) { reg.Registration(dm); } Console.ReadKey(true); }