コード例 #1
0
        public async Task <ActionResult> Profile(EmployeeUserViewModel collection)
        {
            try
            {
                ViewBag.Department = await APIHelpers.GetAsync <List <Departments> >("api/Department/GetDepartments");

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

                string skills = string.Join(",", Request["Skill"]);
                collection.Skills = skills;
                await APIHelpers.PutAsync <Employee>("api/Employee/Put", collection);

                TempData["sucess"] = EmployeeResources.update;
                //string dob = Request["BirthDate"];
                //string skills = string.Join(",", Request["Skill"]);

                //ModelState.Remove("BirthDate");
                //ModelState.Remove("LeaveBalance");
                ////var month = (13 - DateTime.Now.Month) * 1.5;
                //if (ModelState.IsValid)
                //{

                //    collection.BirthDate = DateTime.ParseExact(dob, "dd/MMM/yyyy", null);
                //    collection.LeaveBalance = Convert.ToDecimal(15);
                //    collection.Skills = skills;
                //    // TODO: Add insert logic here
                //    if (collection.Id == Guid.Empty)
                //    {
                //        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 result = await UserManager.CreateAsync(user, collection.Password);
                //        if (result.Succeeded)
                //        {
                //            await APIHelpers.PostAsync<Employee>("api/Employee/Post", collection);
                //            TempData["sucess"] = EmployeeResources.create;
                //        }
                //    }
                //    else
                //    {
                //        await APIHelpers.PutAsync<Employee>("api/Employee/Put", collection);
                //        TempData["sucess"] = EmployeeResources.update;
                //    }
                return(View("Profile", collection));
                //}
                //else
                //{
                //    return View(collection);
                //}
            }
            catch (Exception ex)
            {
                TempData["error"] = CommonResources.error;
                return(RedirectToAction("AccessDenied", "Error"));
            }
        }
コード例 #2
0
        public ActionResult store(EmployeeUserViewModel euViewModel)
        {
            //Get Current UserName
            int id = Convert.ToInt32(User.Identity.Name);
            //Current Compamy
            company find_company = new DBContext().companies.ToList().Find(x => x.user_id == id);

            //Check Model state is valid or not
            if (ModelState.IsValid)
            {
                //Check if already exists
                if (new DBContext().employee_users.ToList().FindAll(x => x.employee_id == euViewModel.VM_EMPLOYEEUSER.employee_id).Count > 0)
                {
                    //Delete The EmployeeUser
                    EmployeeUser existingEmployeeUser = new DBContext().employee_users.ToList().Find(x => x.employee_id == euViewModel.VM_EMPLOYEEUSER.employee_id);
                    using (var contxt = new DBContext())
                    {
                        contxt.Entry(existingEmployeeUser).State = EntityState.Deleted;
                        contxt.SaveChanges();
                    }
                }
                //Add new EmployeeUser
                using (var contxt = new DBContext())
                {
                    //Set Datetime
                    //EmployeeMdl.created_at = DateTime.Now;
                    //set comapmny id
                    //euViewModel.VM_EMPLOYEE.company_id = find_company.id;
                    //Add New EmployeeUser
                    EmployeeUser employeeUser = new EmployeeUser
                    {
                        employee_id = euViewModel.VM_EMPLOYEEUSER.employee_id,
                        user_id     = euViewModel.VM_EMPLOYEEUSER.user_id
                    };
                    contxt.employee_users.Add(employeeUser);
                    contxt.SaveChanges();
                }
                //Set temp data Success registration message
                TempData["message"] = Utility.SUCCESS_MESSAGE + "Employee Assigned Successfully";

                return(RedirectToAction("index"));
            }

            else
            {
                string errors = errorstate.errors(ModelState);
                //Set temp data for wrong credentials
                TempData["message"] = Utility.FAILED_MESSAGE + "" + errors;

                String param_id = euViewModel.VM_EMPLOYEEUSER.employee_id.ToString();
                //redirect back to assign page
                return(RedirectToAction("assign", new { empID = param_id }));
            }
        }
コード例 #3
0
        public static async Task <bool> PostAsync <T>(string uri, EmployeeUserViewModel data)
        {
            var response = await APIHelpers.CallApi(uri, JsonConvert.SerializeObject(data), "POST");

            if (response.IsSuccessStatusCode)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #4
0
 public bool Post(EmployeeUserViewModel model)
 {
     try
     {
         List <CandidateSkills> skills = new List <CandidateSkills>();
         Employee emp = new Employee
         {
             Id                     = Guid.NewGuid(),
             FirstName              = model.FirstName,
             MiddleName             = model.MiddleName,
             LastName               = model.LastName,
             Phone                  = model.Phone,
             BirthDate              = model.BirthDate,
             Address                = model.Address,
             OtherContact           = model.OtherContact,
             Department             = model.Department,
             LeaveBalance           = model.LeaveBalance,
             CurrentSalary          = model.CurrentSalary,
             IsEmailVerified        = model.IsEmailVerified,
             UserId                 = model.UserId,
             JoiningDate            = model.JoiningDate,
             Experience             = model.Experience,
             EmergencyContactName   = model.EmergencyContactName,
             EmergencyContactNumber = model.EmergencyContactNumber,
             BloodGroup             = model.BloodGroup
         };
         var data2 = _repository.Insert(emp);
         if (model.Skills != "")
         {
             foreach (var item in model.Skills.Split(','))
             {
                 skills.Add(new CandidateSkills()
                 {
                     Id          = Guid.NewGuid(),
                     CandidateId = data2.Id,
                     SkillId     = Guid.Parse(item)
                 });
             }
             _skillrepository.InsertRange(skills);
         }
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
コード例 #5
0
        public ActionResult assign(String empID)
        {
            //Get Current UserName
            int user_id = Convert.ToInt32(User.Identity.Name);
            //Current Compamy
            company find_company = new DBContext().companies.ToList().Find(x => x.user_id == user_id);

            //Set  Message
            String message = "";


            int eID = Convert.ToInt32(empID);


            //pass model to view
            Employee mdlEmployee = new Employee();

            //Check if id doesnot null
            if (empID != null && empID != "0")
            {
                //check if Employee already exist
                if (new DBContext().employees.ToList().FindAll(x => x.id == eID).Count > 0)
                {
                    //pass model to view with Employee info
                    mdlEmployee = new DBContext().employees.Find(eID);
                }
            }

            //Check Temp error or successmessage
            if (TempData["message"] != null)
            {
                message = TempData["message"].ToString();
            }


            //view data send message
            ViewData["message"] = message;
            EmployeeUserViewModel vm = new EmployeeUserViewModel();

            vm.VM_EMPLOYEE     = mdlEmployee;
            vm.VM_USER         = new User();
            vm.VM_EMPLOYEEUSER = new EmployeeUser();

            return(View(vm));
        }
コード例 #6
0
        public Employee Put(EmployeeUserViewModel model)
        {
            //return _repository.Update(model);
            List <CandidateSkills> skills = new List <CandidateSkills>();
            Employee emp = new Employee
            {
                Id                     = model.Id,
                FirstName              = model.FirstName,
                MiddleName             = model.MiddleName,
                LastName               = model.LastName,
                Phone                  = model.Phone,
                BirthDate              = model.BirthDate,
                Address                = model.Address,
                OtherContact           = model.OtherContact,
                Department             = model.Department,
                LeaveBalance           = model.LeaveBalance,
                CurrentSalary          = model.CurrentSalary,
                IsEmailVerified        = model.IsEmailVerified,
                UserId                 = model.UserId,
                JoiningDate            = model.JoiningDate,
                Experience             = model.Experience,
                BloodGroup             = model.BloodGroup,
                EmergencyContactNumber = model.EmergencyContactNumber,
                EmergencyContactName   = model.EmergencyContactName,
            };
            var data2 = _repository.Update(emp);

            _skillrepository.DeleteWhere(_ => _.CandidateId == emp.Id);
            if (model.Skills != "")
            {
                foreach (var item in model.Skills.Split(','))
                {
                    skills.Add(new CandidateSkills()
                    {
                        Id          = Guid.NewGuid(),
                        CandidateId = data2.Id,
                        SkillId     = Guid.Parse(item)
                    });
                }
                _skillrepository.InsertRange(skills);
            }

            return(data2);
        }
コード例 #7
0
        // GET: Employee/Edit/5
        /// <summary>
        /// Edits the specified identifier.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        public async Task <ActionResult> Edit(Guid id)
        {
            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();
                var data = await APIHelpers.GetAsync <EmployeeUserViewModel>("api/Employee/GetEmployeeUser/" + id);

                EmployeeUserViewModel emp = new EmployeeUserViewModel
                {
                    Id                     = data.Id,
                    FirstName              = data.FirstName,
                    MiddleName             = data.MiddleName,
                    LastName               = data.LastName,
                    Address                = data.Address,
                    BirthDate              = data.BirthDate,
                    Phone                  = data.Phone,
                    OtherContact           = data.OtherContact,
                    CurrentSalary          = data.CurrentSalary,
                    LeaveBalance           = data.LeaveBalance,
                    IsEmailVerified        = data.IsEmailVerified,
                    UserId                 = data.UserId,
                    Department             = data.Department,
                    Skills                 = data.Skills,
                    JoiningDate            = data.JoiningDate,
                    Experience             = data.Experience,
                    EmergencyContactName   = data.EmergencyContactName,
                    EmergencyContactNumber = data.EmergencyContactNumber,
                    BloodGroup             = data.BloodGroup
                };
                var temp = await APIHelpers.GetAsync <List <ProjectViewModel> >("api/Employee/Projects/" + data.UserId);

                emp.Projects = temp;
                return(View("Create", emp));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("AccessDenied", "Error"));
            }
        }
コード例 #8
0
        // GET: Employee/Create
        /// <summary>
        /// Creates this instance.
        /// </summary>
        /// <returns></returns>
        public async Task <ActionResult> Create()
        {
            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();
                var m = new EmployeeUserViewModel()
                {
                    BirthDate = DateTime.Today
                };
                return(View(m));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("AccessDenied", "Error"));
            }
        }
コード例 #9
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"));
            }
        }