示例#1
0
        public bool AddManager(UserType composite)
        {
            var tables = new LinqWorkerDataContext();

            if (tables.Users.All(x => x.Login != composite.Login))
            {
                string type="user", message=string.Empty;

                var manager = new Users()
                    {
                        Fio = composite.Fio,
                        Login = composite.Login,
                        Password = composite.Password
                    };

                try
                {
                    String command =
                        String.Format(
                            "INSERT INTO dbo.Users(Fio,Login,Password) VALUES(\'{0}\',\'{1}\',\'{2}\')",
                            manager.Fio,
                            manager.Login,
                            manager.Password
                            );

                    tables.ExecuteCommand(command);

                    message = "Добавлен новый пользователь : " + composite.Fio;
                    return true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    message = "Ошибка при добавление пользователя : " + composite.Fio;
                    type = "system";
                    return false;
                }
                finally
                {
                    AddLog(type, message, DateTime.Now.ToString("MM/dd/yyyy HH:mm"));
                }
            }
            return false;
        }
示例#2
0
        public bool UpdateManager(UserType composite)
        {
            var tables = new LinqWorkerDataContext();
            string type = "user", message = string.Empty;
            try
            {
                var manager = tables.Users.Single(c => c.Id == composite.Id);

                manager.Fio = composite.Fio;
                manager.Login = composite.Login;
                manager.Password = composite.Password;

                tables.Users.Context.SubmitChanges();

                message = "Обновление пользователя : " + composite.Fio;
                return true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                message = "Ошибка при обновление пользователя : " + composite.Fio;
                type = "system";
                return false;
            }
            finally
            {
                AddLog(type, message, DateTime.Now.ToString("MM/dd/yyyy HH:mm"));
            }
            /*
                        return false;
            */
        }
示例#3
0
        public int SignIn(UserType composite)
        {
            var tables = new LinqWorkerDataContext();
            string type = "user", message = string.Empty;
            try
            {
                var manager = tables.Users.Single(c => c.Login == composite.Login);
                int number;
                if (manager.Password == composite.Password)
                {
                    message = "Вход в систему : " + composite.Fio;
                    number = manager.Id;
                }
                else
                {
                    message = "Ошибка входа в систему : " + composite.Fio;
                    number = -1;
                }

                return number;
            }
            catch (Exception ex)
            {
                message = "Ошибка при входе пользователя в систему : " + composite.Fio;
                type = "system";
                return -1;
            }
            finally
            {
                AddLog(type, message, DateTime.Now.ToString("MM/dd/yyyy HH:mm"));
            }
        }
示例#4
0
        public bool DeleteManager(UserType composite)
        {
            var tables = new LinqWorkerDataContext();
            string type = "user", message = string.Empty;
            try
            {
                var manager = tables.Users.Single(c => c.Id == composite.Id);
                tables.Users.DeleteOnSubmit(manager);
                tables.Users.Context.SubmitChanges();

                message = "Пользователь удален : " + composite.Fio;
                return true;
            }
            catch (Exception ex)
            {
                message = "Ошибка при удаление пользователя : " + composite.Fio;
                type = "system";
                return false;
            }
            finally
            {
                AddLog(type, message, DateTime.Now.ToString("MM/dd/yyyy HH:mm"));
            }
            /*
                        return false;
            */
        }