예제 #1
0
        public bool AddStudent(Student student)
        {
            bool right = true;

            if (String.IsNullOrWhiteSpace(student.Name))
            {
                right = false;
            }

            //if (!String.IsNullOrWhiteSpace(student.Inn) && student.Inn.Length > 20)
            //{
            //    right = false;
            //}

            if (!String.IsNullOrWhiteSpace(student.MedPolicy) && student.MedPolicy.Length > 20)
            {
                right = false;
            }

            if (!String.IsNullOrWhiteSpace(student.Snils) && student.Snils.Length > 20)
            {
                right = false;
            }

            if (!String.IsNullOrWhiteSpace(student.Phone) && student.Phone.Length > 20)
            {
                right = false;
            }

            if (!String.IsNullOrWhiteSpace(student.HousePhone) && student.HousePhone.Length > 20)
            {
                right = false;
            }

            if (right)
            {
                try
                {
                    context.Students.Add(student);
                    context.SaveChanges();
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
            return(false);
        }
예제 #2
0
        public bool EditAccountData(AccountModel accountModel)
        {
            var user = context.Users.Where(i => i.UserName == AuthorizedUser.UserName).FirstOrDefault();

            var employee = context.Employees.Where(i => i.UserId == user.Id).FirstOrDefault();

            employee.Name  = accountModel.Name;
            employee.EMail = accountModel.Email;
            user.UserName  = accountModel.Login;
            if (!string.IsNullOrWhiteSpace(accountModel.NewPassword))
            {
                user.Password = accountModel.NewPassword;
            }

            context.Employees.Update(employee);
            context.Users.Update(user);

            try
            {
                context.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }