public async Task <ActionResult> Profile()
        {
            try
            {
                var empId = CommonHelper.CurrentEmployeeId();
                ViewBag.Department = await APIHelpers.GetAsync <List <Departments> >("api/Department/GetDepartments");

                ViewBag.Skills = await APIHelpers.GetAsync <List <Skills> >("api/Skill/GetSkills");

                ViewBag.Roles = _applicationDbContext.Roles.ToList();
                var temp = await APIHelpers.GetAsync <EmployeeUserViewModel>("api/Employee/GetEmployeeUser/" + empId);

                return(View(temp));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Beispiel #2
0
        public async Task <ActionResult> Create(EmployeeUserViewModel collection)
        {
            try
            {
                ViewBag.Department = await APIHelpers.GetAsync <List <Departments> >("api/Department/GetDepartments");

                ViewBag.Skills = await APIHelpers.GetAsync <List <Skills> >("api/Skill/GetSkills");

                ViewBag.Roles = _applicationDbContext.Roles.ToList();
                string skills = string.Join(",", Request["Skill"]);
                ModelState.Remove("BirthDate");
                ModelState.Remove("JoiningDate");
                ModelState.Remove("LeaveBalance");
                ModelState.Remove("OtherContact");
                ModelState.Remove("Skills");
                //var month = (13 - DateTime.Now.Month) * 1.5;

                if (collection.Id == Guid.Empty)
                {
                    if (ModelState.IsValid)
                    {
                        collection.Skills = skills;
                        string dob = Request["BirthDate"];
                        collection.BirthDate = DateTime.ParseExact(dob, "MM/dd/yyyy", null);
                        string join = Request["JoiningDate"];
                        collection.JoiningDate = DateTime.ParseExact(join, "MM/dd/yyyy", null);
                        var user = new ApplicationUser {
                            RoleId = collection.RoleId, UserName = collection.Email, IsSuperAdmin = false, ParentUserID = Guid.Parse("06644856-45f6-4c78-9c19-60781abba7e3"), Email = collection.Email, FirstName = "", LastName = "", UserStatus = 0
                        };
                        collection.UserId = Guid.Parse(user.Id);
                        var account = await UserManager.CreateAsync(user, collection.Password);

                        if (account.Succeeded)
                        {
                            var result = await PostAsync <EmployeeUserViewModel>("api/Employee/Post", collection);

                            if (result)
                            {
                                TempData["sucess"] = EmployeeResources.create;
                                return(RedirectToAction("Index"));
                            }
                            else
                            {
                                var delete = await UserManager.DeleteAsync(CommonHelper.GetUserById(user.Id));

                                TempData["error"] = CommonResources.error;
                                return(View(collection));
                            }
                        }
                        else
                        {
                            string msg = "";
                            foreach (var error in account.Errors)
                            {
                                ModelState.AddModelError("", error);
                                msg += error + Environment.NewLine;
                            }
                            //await APIHelpers.DeleteAsync<bool>("api/Employee/Delete/" + data.Id);
                            TempData["error"] = msg;
                            return(View(collection));
                        }
                    }
                    else
                    {
                        return(View(collection));
                    }
                }
                else
                {
                    ModelState.Remove("Password");
                    ModelState.Remove("Email");
                    if (ModelState.IsValid)
                    {
                        string dob = Request["BirthDate"];
                        collection.BirthDate = DateTime.ParseExact(dob, "MM/dd/yyyy", null);
                        collection.Skills    = skills;
                        await APIHelpers.PutAsync <Employee>("api/Employee/Put", collection);

                        TempData["sucess"] = EmployeeResources.update;
                    }
                    else
                    {
                        return(RedirectToAction("Edit", new RouteValueDictionary(
                                                    new { action = "Edit", Id = collection.Id })));
                        //return View(collection);
                    }
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                TempData["error"] = CommonResources.error;
                return(RedirectToAction("AccessDenied", "Error"));
            }
        }