public async Task <IHttpActionResult> DeleteUser(UserViewModel model)
        {
            if (model == null)
            {
                return(Ok(new { status = false, data = "", message = "Invalid data model." }));
            }

            if (model.UserType == UserType.BusinessEmployee)
            {
                var employe = model.BusinessEmployee;
                var businessEmployeeController = new BusinessEmployeeController();
                using (var appointmetntDb = _dbAppointment.Database.BeginTransaction())
                {
                    try
                    {
                        var deleteEmploye = businessEmployeeController.DeleteEmployee(employe.Id);
                        if (deleteEmploye.Status)
                        {
                            var user = await UserManager.FindByEmailAsync(deleteEmploye.Data.Email);

                            var response = await UserManager.DeleteAsync(user);

                            if (response.Succeeded)
                            {
                                return(Ok(new { status = true, data = deleteEmploye.Data, message = "deleted successfully." }));
                            }
                            else
                            {
                                appointmetntDb.Rollback();
                                return(Ok(new { status = false, data = deleteEmploye.Data, message = "deletion failed. ex:" + response.Errors }));
                            }
                        }
                        else
                        {
                            appointmetntDb.Rollback();
                            return(Ok(new { status = false, data = "", message = "There was problem. Please try again later." }));
                        }
                    }
                    catch
                    {
                        appointmetntDb.Rollback();
                        return(Ok(new { status = false, data = "", message = "There was a problem Please try again later." }));
                    }
                }
            }
            else if (model.UserType == UserType.BusinessCustomer)
            {
                var customer = model.BusinessCustomer;
                var businessCustomerController = new BusinessCustomerController();
                using (var appointmetntDb = _dbAppointment.Database.BeginTransaction())
                {
                    try
                    {
                        var deleteCustomer = businessCustomerController.DeleteCustomer(customer.Id);
                        if (deleteCustomer.Status)
                        {
                            var user = await UserManager.FindByEmailAsync(deleteCustomer.Data.Email);

                            var response = await UserManager.DeleteAsync(user);

                            if (response.Succeeded)
                            {
                                return(Ok(new { status = true, data = deleteCustomer.Data, message = "deleted successfully." }));
                            }
                            else
                            {
                                appointmetntDb.Rollback();
                                return(Ok(new { status = false, data = deleteCustomer.Data, message = "deletion failed. ex:" + response.Errors }));
                            }
                        }
                        else
                        {
                            appointmetntDb.Rollback();
                            return(Ok(new { status = false, data = "", message = "There was problem. Please try again later." }));
                        }
                    }
                    catch
                    {
                        appointmetntDb.Rollback();
                        return(Ok(new { status = false, data = "", message = "There was a problem Please try again later." }));
                    }
                }
            }
            else
            {
                return(Ok(new { status = false, data = "", message = "Invalid user." }));
            }
        }
        public async Task <IHttpActionResult> Register(UserViewModel model)
        {
            //var result = new ResponseViewModel<tblAdministrator>();

            if (model == null)
            {
                return(Ok(new { status = false, data = "", message = "Invalid data model." }));
            }

            if (model.UserType == UserType.SiteAdmin)
            {
                var admin           = model.SiteAdmin;
                var adminController = new AdministratorController();
                using (var appointmetntDb = _dbAppointment.Database.BeginTransaction())
                {
                    try
                    {
                        var registerViewModel = adminController.RegisterAdmin(admin);
                        if (registerViewModel.Status)
                        {
                            var user = new ApplicationUser()
                            {
                                UserName = admin.Email, Email = admin.Email
                            };
                            var password = HttpContext.Current.Server.UrlDecode(admin.Password);
                            var response = await UserManager.CreateAsync(user, password);

                            if (response.Succeeded)
                            {
                                appointmetntDb.Commit();
                                return(Ok(new { status = true, data = registerViewModel, message = "Registeration successfully." }));
                            }
                            else
                            {
                                appointmetntDb.Rollback();
                                return(Ok(new { status = false, data = registerViewModel, message = "Registeration failed. ex:" + response.Errors }));
                            }
                        }
                        else
                        {
                            appointmetntDb.Rollback();
                            return(Ok(new { status = false, data = "", message = registerViewModel.Message }));
                        }
                    }
                    catch
                    {
                        appointmetntDb.Rollback();
                        var user = UserManager.FindByEmail(model.SiteAdmin.Email);
                        if (user != null)
                        {
                            UserManager.Delete(user);
                        }
                        return(Ok(new { status = false, data = "", message = "There was a problem to register account, Please try again later." }));
                    }
                }
            }
            else if (model.UserType == UserType.BusinessAdmin)
            {
                var businessAdmin      = model.BusinessAdmin;
                var businessController = new BusinessController();
                using (var appointmetntDb = _dbAppointment.Database.BeginTransaction())
                {
                    try
                    {
                        var registerViewModel = businessController.Register(businessAdmin);
                        if (registerViewModel.Status)
                        {
                            var user = new ApplicationUser()
                            {
                                UserName = businessAdmin.Employee.Email, Email = businessAdmin.Employee.Email
                            };
                            var password = HttpContext.Current.Server.UrlDecode(businessAdmin.Employee.Password);
                            var response = await UserManager.CreateAsync(user, password);

                            if (response.Succeeded)
                            {
                                appointmetntDb.Commit();
                                return(Ok(new { status = true, data = registerViewModel, message = "Registeration successfully." }));
                            }
                            else
                            {
                                appointmetntDb.Rollback();
                                return(Ok(new { status = false, data = registerViewModel, message = "Registeration failed. ex:" + response.Errors }));
                            }
                        }
                        else
                        {
                            appointmetntDb.Rollback();
                            return(Ok(new { status = false, data = registerViewModel, message = "There was problem. Please try again later." }));
                        }
                    }
                    catch
                    {
                        appointmetntDb.Rollback();
                        var user = UserManager.FindByEmail(businessAdmin.Employee.Email);
                        if (user != null)
                        {
                            UserManager.Delete(user);
                        }
                        return(Ok(new { status = false, data = "", message = "There was a problem to register account, Please try again later." }));
                    }
                }
            }
            else if (model.UserType == UserType.BusinessEmployee)
            {
                var businessEmployee           = model.BusinessEmployee;
                var businessEmployeeController = new BusinessEmployeeController();
                using (var appointmetntDb = _dbAppointment.Database.BeginTransaction())
                {
                    try
                    {
                        var registerViewModel = businessEmployeeController.Register(businessEmployee);
                        if (registerViewModel.Status)
                        {
                            var user = new ApplicationUser()
                            {
                                UserName = businessEmployee.Email, Email = businessEmployee.Email
                            };
                            var password = HttpContext.Current.Server.UrlDecode(businessEmployee.Password);
                            var response = await UserManager.CreateAsync(user, password);

                            if (response.Succeeded)
                            {
                                appointmetntDb.Commit();
                                return(Ok(new { status = true, data = registerViewModel.Data, message = "Registeration successfully." }));
                            }
                            else
                            {
                                appointmetntDb.Rollback();
                                return(Ok(new { status = false, data = registerViewModel.Data, message = "Registeration failed. ex:" + response.Errors }));
                            }
                        }
                        else
                        {
                            appointmetntDb.Rollback();
                            return(Ok(new { status = false, data = "", message = "There was problem. Please try again later." }));
                        }
                    }
                    catch
                    {
                        appointmetntDb.Rollback();
                        var user = UserManager.FindByEmail(businessEmployee.Email);
                        if (user != null)
                        {
                            UserManager.Delete(user);
                        }
                        return(Ok(new { status = false, data = "", message = "There was a problem to register account, Please try again later." }));
                    }
                }
            }
            else if (model.UserType == UserType.BusinessCustomer)
            {
                var businessCustomer           = model.BusinessCustomer;
                var businessCustomerController = new BusinessCustomerController();
                using (var appointmetntDb = _dbAppointment.Database.BeginTransaction())
                {
                    try
                    {
                        var registerViewModel = businessCustomerController.Register(businessCustomer);
                        if (registerViewModel.Status)
                        {
                            var user = new ApplicationUser()
                            {
                                UserName = businessCustomer.Email, Email = businessCustomer.Email
                            };
                            var password = HttpContext.Current.Server.UrlDecode(businessCustomer.Password);
                            var response = await UserManager.CreateAsync(user, password);

                            if (response.Succeeded)
                            {
                                appointmetntDb.Commit();
                                return(Ok(new { status = true, data = registerViewModel.Data, message = "Registeration successfully." }));
                            }
                            else
                            {
                                appointmetntDb.Rollback();
                                return(Ok(new { status = false, data = registerViewModel.Data, message = "Registeration failed. ex:" + response.Errors }));
                            }
                        }
                        else
                        {
                            appointmetntDb.Rollback();
                            return(Ok(new { status = false, data = "", message = "There was problem. Please try again later." }));
                        }
                    }
                    catch
                    {
                        appointmetntDb.Rollback();
                        var user = UserManager.FindByEmail(businessCustomer.Email);
                        if (user != null)
                        {
                            UserManager.Delete(user);
                        }
                        return(Ok(new { status = false, data = "", message = "There was a problem to register account, Please try again later." }));
                    }
                }
            }
            else
            {
                return(Ok(new { status = false, data = "", message = "Invalid user." }));
            }
        }