public ActionResult EngagementType(string LeaveTypeId, string LeaveTypeName, string ShortName, string LeaveTypeCategory, string EffectiveFrom, string YearEndAction, Int16 MaxLimit = 0, Int64 EngagementTypeId = 0, Int16 SchemeId = 0, int LeaveLimit = 0)
        {
            var UserDetail = generic.GetUserDetail(User.Identity.GetUserId());

            ViewData["EmpDetails"]  = ems.GetEmployeeBasicDetails(UserDetail.UserId).FirstOrDefault();
            ViewData["CompanyLogo"] = cms.GetCompanyLogo(UserDetail.SubscriberId).FirstOrDefault();
            string CorporateId = UserDetail.SubscriberId;

            DateTime EffectiveDate = DateTime.Now;

            if (!String.IsNullOrEmpty(EffectiveFrom))
            {
                EffectiveDate = DateTime.ParseExact(EffectiveFrom, "dd-MM-yyyy", CultureInfo.InvariantCulture);
            }
            bool result = ems.AddEngagementTypeMaster(EngagementTypeId, LeaveTypeName, CorporateId, ShortName, SchemeId, LeaveTypeId, LeaveTypeCategory, LeaveLimit, EffectiveDate, YearEndAction, MaxLimit);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var result   = new IdentityResult();
                var password = Encrypt(model.Password);
                //var mypass = Decrypt(password);
                LoginViewModel loginEm = admin.GetLoginDetails(model.Email);
                if (loginEm != null)
                {
                    ModelState.AddModelError("", "Email '" + model.Email + "' is already taken.");
                }

                LoginViewModel loginPh = admin.GetLoginDetails(model.PhoneNumber);
                if (loginPh != null)
                {
                    ModelState.AddModelError("", "Phone Number '" + model.PhoneNumber + "' is already taken.");
                }

                if (loginEm == null && loginPh == null)
                {
                    string ModuleName = String.IsNullOrEmpty(Convert.ToString(TempData["ModuleName"])) ? "CMS" : Convert.ToString(TempData["ModuleName"]);
                    model.UserName = admin.GenerateUserName();
                    var user = new ApplicationUser {
                        UserName = model.UserName, Email = model.Email, PhoneNumber = model.PhoneNumber
                    };
                    result = await UserManager.CreateAsync(user, model.Password);

                    if (result.Succeeded)
                    {
                        await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                        var status = UserManager.AddToRole(user.Id, "Admin");

                        if (status.Succeeded)
                        {
                            model.UpdatedBy = Convert.ToString(User.Identity.GetUserId());
                            model.UpdatedOn = DateTime.UtcNow;
                            model.Pcode     = password;
                            admin.UserRegistration(user.Id, model.Name, DateTime.UtcNow, ModuleName, "ADI", "Admin", user.Id, model.ManagerLevel, model.ReportingAuthority, model.UpdatedOn, model.UpdatedBy, model.RegistrationId, model.Pcode, model.Source);
                            bool i = admin.AddJobOrderType(null, user.Id);

                            //Adding Item Type Maters For Joborders & Tasks
                            admin.AddItemTypeMaster(0, null, user.Id);

                            //Adding By Default Engagement type masters
                            var SchemeMasters = db.LeaveSchemeMaster.ToList();
                            {
                                foreach (var item in SchemeMasters)
                                {
                                    var defaultEngagements = db.LeaveType.ToList();
                                    foreach (var qitem in defaultEngagements)
                                    {
                                        Int64 EngagementTypeId = 0;
                                        ems.AddEngagementTypeMaster(EngagementTypeId, qitem.LeaveTypeName, user.Id, qitem.LeaveTypeId, item.SchemeId, qitem.LeaveTypeId, qitem.LeaveTypeCategory, 0, DateTime.Now, null, 0);
                                    }
                                }
                            }
                            //LMS (WIKIPIAN) Plan must be checked here

                            //await RegisterToLMS(model, user.Id);

                            //await RegisterToPrelore(model, user.Id);
                        }
                        //IMP
                        //string callbackUrl = await SendEmailConfirmationTokenAsync(user.Id, "Welcome to Blink", model.UserName, model.PhoneNumber, model.Name);

                        // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                        // Send an email with this link
                        // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                        // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                        // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                        return(RedirectToAction("Index", "Dashboard", new { area = "CMS" }));
                        //return RedirectToAction("Plan", "Plan_Pricing", new { area = "Admin" });
                    }
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }