Пример #1
0
        public Boolean RegisterEmployee(RegisterActive reg)
        {
            try
            {
                GetEmail getEmail = new GetEmail();
                getEmail.Email = reg.RegisterEmpEmail;

                if (this.IsEmailUnique(getEmail) == false)
                {
                    var data = _context.Employees
                               .Where(c => c.EmpEmail == reg.RegisterEmpEmail && c.RegisterCode == reg.RegisterCode)
                               .Select(c => c.EmpEmail)
                               .FirstOrDefault();

                    if (string.IsNullOrEmpty(data))
                    {
                        return(false);
                    }
                    else
                    {
                        var employee = _context.Employees.Where(c => c.EmpEmail == reg.RegisterEmpEmail && c.RegisterCode == reg.RegisterCode).FirstOrDefault();
                        employee.IsActive = true;
                        _context.Entry(employee).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                        _context.SaveChanges();
                        return(true);
                    }
                }
                return(false);
            } catch { return(false); }
        }
 public IActionResult RegisterEmployee([FromBody] RegisterActive reg)
 {
     if (_service.RegisterEmployee(reg))
     {
         return(Ok());
     }
     else
     {
         return(BadRequest());
     }
 }
Пример #3
0
        /// <summary>
        /// register employee using regiter code
        /// </summary>
        /// <param name="reg"></param>
        /// <returns> if success return true</returns>
        public Boolean RegisterEmployee(RegisterActive reg)
        {
            try
            {
                GetEmail getEmail = new GetEmail();
                getEmail.Email = reg.RegisterEmpEmail;

                if (this.IsEmail(getEmail) == false)
                {
                    var data = _context.Employees
                               .Where(c => c.EmpEmail == reg.RegisterEmpEmail && c.RegisterCode == reg.RegisterCode)
                               .Select(c => c.EmpEmail)
                               .FirstOrDefault();

                    if (string.IsNullOrEmpty(data))
                    {
                        return(false);
                    }
                    else
                    {
                        //create new  random number for register code
                        Random rand        = new Random((int)DateTime.Now.Ticks);
                        int    regitercode = rand.Next(10000, 99999);

                        var employee = _context.Employees.Where(c => c.EmpEmail == reg.RegisterEmpEmail && c.RegisterCode == reg.RegisterCode).FirstOrDefault();
                        employee.IsActive              = true;
                        employee.RegisterCode          = regitercode.ToString();
                        _context.Entry(employee).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                        _context.SaveChanges();
                        return(true);
                    }
                }
                return(false);
            }
            catch { return(false); }
        }
 public Boolean RegisterEmployee(RegisterActive reg)
 {
     return(_service.RegisterEmployee(reg));
 }