コード例 #1
0
        public static bool Validate(Employee entity)
        {
            if (entity.FirstName == null || entity.FirstName.Trim().Length == 0)
            {
                Methods.ShowStandardMsgBox(FormMessageType.Error, RscError.ValidationTitle, RscError.EmployeeFirstNameNull);
                return false;
            }

            if (entity.LastName == null || entity.LastName.Trim().Length == 0)
            {
                Methods.ShowStandardMsgBox(FormMessageType.Error, RscError.ValidationTitle, RscError.EmployeeLastNameNull);
                return false;
            }

            if (entity.Role == null)
            {
                Methods.ShowStandardMsgBox(FormMessageType.Error, RscError.ValidationTitle, RscError.EmployeeRoleNull);
                return false;
            }

            if (entity.CanLogin)
            {
                if (entity.Username == null || entity.Username.Trim().Length == 0)
                {
                    Methods.ShowStandardMsgBox(FormMessageType.Error, RscError.ValidationTitle, RscError.EmployeeUsernameNull);
                    return false;
                }

                if (DataLayer.HasUsername(entity))
                {
                    Methods.ShowStandardMsgBox(FormMessageType.Error, RscError.ValidationTitle, RscError.EmployeeUsernameDuplicate);
                    return false;
                }

                if (entity.Password == null || entity.Password.Trim().Length == 0)
                {
                    Methods.ShowStandardMsgBox(FormMessageType.Error, RscError.ValidationTitle, RscError.EmployeePasswordNull);
                    return false;
                }
            }

            return true;
        }
コード例 #2
0
ファイル: DataLayer.cs プロジェクト: Ashna/ShayanDent
        public static bool Remove(Employee item)
        {
            EntityModelContainer context = GetContext();

            try
            {
                context.DeleteObject(item);
            }
            catch
            {
                Methods.ShowStandardMsgBox(FormMessageType.Error, RscError.ErrorTitle, RscError.EntityDelete);
                context.ObjectStateManager.ChangeObjectState(item, System.Data.EntityState.Modified);
                return false;
            }
            return true;
        }
コード例 #3
0
ファイル: DataLayer.cs プロジェクト: Ashna/ShayanDent
        public static void Insert(Employee item)
        {
            EntityModelContainer context = GetContext();

            if (item.EntityState != EntityState.Added)
            {
                context.AddObject(item.GetType().Name + "s", item);
            }
            if (item.UserSetting == null)
            {
                UserSettings userSetting = new UserSettings
                                               {
                                                   HolidayColor = (int) Constants.Color.Green,
                                                   WorkHourColor = (int) Constants.Color.White,
                                                   DayColor = (int) Constants.Color.NoColor,
                                                   TimeSlotDuration = 2,
                                                   ActiveViewType = 2,
                                                   NamingConvention = 0
                                               };
                item.UserSetting = userSetting;
            }
        }
コード例 #4
0
ファイル: DataLayer.cs プロジェクト: Ashna/ShayanDent
 public static void Attach(Employee employee)
 {
     EntityModelContainer context = GetContext();
     context.AttachTo("Employees", employee);
 }
コード例 #5
0
ファイル: DataLayer.cs プロジェクト: Ashna/ShayanDent
        public static bool HasUsername(Employee entity)
        {
            EntityModelContainer context = entity.Context;

            if (entity.EntityState == EntityState.Unchanged)
                return false;

            if (context.ObjectStateManager.GetObjectStateEntries
                ((EntityState.Added | EntityState.Modified | EntityState.Unchanged))
                .Select(e => e.Entity).OfType<Employee>()
                .Any
                (
                    x =>
                    ((x.Id!=0 && x.Id != entity.Id) || (x.Id==0 && x!=entity))
                    && x.Username != null
                    && x.Username == entity.Username)
                )
                return true;

            return false;
        }
コード例 #6
0
ファイル: DataLayer.cs プロジェクト: Ashna/ShayanDent
        public static bool HasSameEntity(Employee entity)
        {
            EntityModelContainer context = entity.Context;

            if (context.ObjectStateManager.GetObjectStateEntries
                ((EntityState.Added | EntityState.Modified | EntityState.Unchanged))
                .Select(e => e.Entity).OfType<Employee>()
                .Any(x => x.FirstName == entity.FirstName
                && x.LastName == entity.LastName && (x.Id == -1 || x.Id != entity.Id)))
                return true;

            return false;
        }
コード例 #7
0
ファイル: DataLayer.cs プロジェクト: Ashna/ShayanDent
 public static void ChangeUserPassword(Employee employee, string password)
 {
     EntityModelContainer context = GetContext();
     Employee emp =
         context.Employees.Execute(MergeOption.OverwriteChanges).Single(e => e.Id == employee.Id);
     emp.Password = password;
     context.SaveChanges();
 }
コード例 #8
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Employees EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToEmployees(Employee employee)
 {
     base.AddObject("Employees", employee);
 }
コード例 #9
0
 /// <summary>
 /// Create a new Employee object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="firstName">Initial value of the FirstName property.</param>
 /// <param name="lastName">Initial value of the LastName property.</param>
 /// <param name="isMale">Initial value of the IsMale property.</param>
 /// <param name="canLogin">Initial value of the CanLogin property.</param>
 /// <param name="roleId">Initial value of the RoleId property.</param>
 /// <param name="monthlySalary">Initial value of the MonthlySalary property.</param>
 /// <param name="incomePercentage">Initial value of the IncomePercentage property.</param>
 /// <param name="userSettingsId">Initial value of the UserSettingsId property.</param>
 /// <param name="isDoctor">Initial value of the IsDoctor property.</param>
 public static Employee CreateEmployee(global::System.Int32 id, global::System.String firstName, global::System.String lastName, global::System.Boolean isMale, global::System.Boolean canLogin, global::System.Int32 roleId, global::System.Double monthlySalary, global::System.Double incomePercentage, global::System.Int32 userSettingsId, global::System.Boolean isDoctor)
 {
     Employee employee = new Employee();
     employee.Id = id;
     employee.FirstName = firstName;
     employee.LastName = lastName;
     employee.IsMale = isMale;
     employee.CanLogin = canLogin;
     employee.RoleId = roleId;
     employee.MonthlySalary = monthlySalary;
     employee.IncomePercentage = incomePercentage;
     employee.UserSettingsId = userSettingsId;
     employee.IsDoctor = isDoctor;
     return employee;
 }