Пример #1
0
        /// <summary>
        /// Insert User into the context (SCAPEDB in this case)
        /// </summary>
        /// <param name="user">User to insert</param>
        public async Task <bool> insertUser(User user)
        {
            _context.User.Add(user);
            await _context.SaveChangesAsync();

            return(true);
        }
Пример #2
0
        /// <summary>
        /// Insert Attendance into the context (SCAPEDB in this case)
        /// </summary>
        /// <param name="attendance">Attendance to insert</param>
        public async Task <bool> insertAttendance(Attendance attendance)
        {
            _context.Attendance.Add(attendance);
            await _context.SaveChangesAsync();

            return(true);
        }
Пример #3
0
        /// <summary>
        /// Insert employee into the context (SCAPEDB in this case)
        /// </summary>
        /// <param name="employee">Employee to insert</param>
        public async Task <bool> insertEmployee(Employee employee)
        {
            try
            {
                _context.Employee.Add(employee);
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                if (ex.GetBaseException().GetType() == typeof(SqlException))
                {
                    Int32 errorCode = ((SqlException)ex.InnerException).Number;

                    if (errorCode == 2627 || errorCode == 2601)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }