Beispiel #1
0
        public ActionResult Update(int Id)
        {
            employee            empdata     = dbcontext.employee.Where(a => a.id == Id).FirstOrDefault();
            List <familyDetail> famdetail   = dbcontext.familyDetail.Where(a => a.employeeId == Id).ToList();
            List <experience>   experiences = dbcontext.experience.Where(a => a.employeeId == Id).ToList();

            if (empdata == null)
            {
                return(HttpNotFound());
            }

            EmployeeFamilyViewModel empFamilyViewModel = new EmployeeFamilyViewModel()
            {
                id            = empdata.id,
                fullName      = empdata.fullName,
                gender        = empdata.gender,
                dob           = empdata.dob,
                email         = empdata.email,
                bloodGroup    = empdata.bloodGroup,
                cAddress      = empdata.cAddress,
                FamilyDetails = famdetail,
                Experiences   = experiences
            };


            return(View("Create", empFamilyViewModel));
        }
        public ActionResult EditFamily(int id)
        {
            EmployeeFamilyViewModel res = new EmployeeFamilyViewModel();

            res        = _empFamilyService.GetEmpFamilyByID(id);
            res.FDobNP = NepEngDate.EngToNep(Convert.ToDateTime(res.FDob));
            return(View(res));
        }
Beispiel #3
0
        public ActionResult Create()
        {
            EmployeeFamilyViewModel empdata = new EmployeeFamilyViewModel();

            //employee empdata = new employee();
            //familyDetail familydetail = new familyDetail();

            //commonViewModel emoployeedetails.emaploye = empdata;

            return(View(empdata));
        }
        public ActionResult EditFamily(EmployeeFamilyViewModel data)
        {
            data.FDob    = Convert.ToDateTime(NepEngDate.NepToEng(data.FDobNP));
            data.EmpCode = Convert.ToInt32(Session["EmpCode"]);
            EmployeeFamilyViewModel jtd = new EmployeeFamilyViewModel();
            //if (!ModelState.IsValid)
            //{
            //    return View(jtd);
            //}

            int res = _empFamilyService.UpdateEmpFamily(data);

            ViewBag.Success = "Education of " + data.EmpCode + " has been updated";
            ModelState.Clear();
            return(View(jtd));
        }
Beispiel #5
0
        public async Task <IActionResult> Family(string id,
                                                 EmployeeFamilyViewModel employeeFamilyViewModel)
        {
            await _EmployeeFamilySaveService.HandleAsync(new EmployeeFamilySaveRequest()
            {
                EmployeeId   = id,
                HumanId      = employeeFamilyViewModel.Family.HumanId,
                FirstName    = employeeFamilyViewModel.Family.FirstName,
                LastName     = employeeFamilyViewModel.Family.LastName,
                Birthday     = employeeFamilyViewModel.Family.Birthday,
                Sex          = employeeFamilyViewModel.Family.Sex,
                RelationShip = employeeFamilyViewModel.Family.RelationShip
            });

            return(RedirectToAction(nameof(Family), new { id = id }));
        }
Beispiel #6
0
 public static EmployeeFamily ConvertRespondentInfoFromDTO(EmployeeFamilyViewModel empFamily)
 {
     Mapper.CreateMap <EmployeeFamilyViewModel, EmployeeFamily>().ConvertUsing(
         m =>
     {
         return(new EmployeeFamily
         {
             EmpCode = m.EmpCode,
             FamilyId = m.FamilyId,
             FContactAddress = m.FContactAddress,
             FContactNumber = m.FContactNumber,
             FDob = m.FDob,
             FGender = m.FGender,
             Fname = m.Fname,
             FRelation = m.FRelation
         });
     });
     return(Mapper.Map <EmployeeFamilyViewModel, EmployeeFamily>(empFamily));
 }
        public ActionResult AddFamily(EmployeeFamilyViewModel data)
        {
            data.FDob = Convert.ToDateTime(NepEngDate.NepToEng(data.FDobNP));

            data.EmpCode = Convert.ToInt32(Session["EmpCode"]);
            EmployeeFamilyViewModel employeeEducation = new EmployeeFamilyViewModel();
            //employeeEducation.CountryList = _empEducationService.GetCountryList();
            //employeeEducation.EducationLevelList = _empEducationService.GetEducationLevelList();

            //if (!ModelState.IsValid)
            //{
            //    return View(employeeEducation);
            //}
            EmployeeFamilyViewModel res = new EmployeeFamilyViewModel();

            res             = _empFamilyService.InsertEmpFamily(data);
            ViewBag.Success = "family of " + res.EmpCode + " has been created";
            ModelState.Clear();
            return(View(employeeEducation));
        }
        public static EmployeeFamilyViewModel ToFamilyViewModel(EmployeeFamilyReferenceResponse response)
        {
            var viewModel = new EmployeeFamilyViewModel()
            {
                EmployeeId = response.EmployeeID,
                Family     = new Family(),
                Families   = new List <Family>()
            };

            response.Families.ForEach(e => viewModel.Families.Add(
                                          new Family(
                                              humanId: e.HumanId.ToString(),
                                              lastName: e.LastName,
                                              firstName: e.FirstName,
                                              relationShip: e.RelationShip,
                                              sex: e.Sex,
                                              birthday: e.BirthDay
                                              )));
            return(viewModel);
        }
Beispiel #9
0
        public int UpdateEmpFamily(EmployeeFamilyViewModel data)
        {
            EmployeeFamily rnk = EmpFamilyRequestFormatter.ConvertRespondentInfoFromDTO(data);

            return(_unitOfWork.EmployeeFamilyRepository.Update(rnk));
        }
Beispiel #10
0
        public EmployeeFamilyViewModel InsertEmpFamily(EmployeeFamilyViewModel data)
        {
            EmployeeFamily rnk = EmpFamilyRequestFormatter.ConvertRespondentInfoFromDTO(data);

            return(EmpFamilyRequestFormatter.ConvertRespondentInfoToDTO(_unitOfWork.EmployeeFamilyRepository.Create(rnk)));
        }
Beispiel #11
0
        public EmployeeFamilyViewModel GetEmpFamilyByID(int rankId)
        {
            EmployeeFamilyViewModel rank = EmpFamilyRequestFormatter.ConvertRespondentInfoToDTO(_unitOfWork.EmployeeFamilyRepository.GetById(rankId));

            return(rank);
        }
Beispiel #12
0
        public ActionResult Create(EmployeeFamilyViewModel empdata, HttpPostedFileBase photo)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (empdata.id == 0) // create section
                    {
                        if (photo != null && photo.ContentLength > 0)
                        {
                            string photopath = Server.MapPath("~/UserImage");
                            if (!Directory.Exists(photopath))
                            {
                                Directory.CreateDirectory(photopath);
                            }
                            string[] imageName = photo.FileName.Split('.').ToArray();
                            string   extension = imageName[(imageName.Length - 1)].ToString();
                            string   fileName  = DateTime.Now.ToString("yyMMddmmhhss") + "_" + photo.FileName + "." + extension;
                            string   filePath  = Path.Combine(photopath, fileName);
                            photo.SaveAs(filePath); //saving photo
                            empdata.photo = fileName;
                        }

                        employee newEmpData = new employee();
                        newEmpData.fullName      = empdata.fullName;
                        newEmpData.dob           = empdata.dob;
                        newEmpData.gender        = empdata.gender;
                        newEmpData.maritalStatus = empdata.maritalStatus;
                        newEmpData.bloodGroup    = empdata.bloodGroup;
                        newEmpData.photo         = empdata.photo;
                        newEmpData.createdBy     = User.Identity.Name;
                        newEmpData.createdDate   = DateTime.Now;
                        dbcontext.employee.Add(newEmpData);

                        dbcontext.SaveChanges();

                        foreach (var item in empdata.FamilyDetails)
                        {
                            familyDetail famData = new familyDetail();
                            famData.relationship = item.relationship;
                            famData.employeeId   = newEmpData.id;
                            famData.name         = item.name;
                            famData.occupation   = item.occupation;
                            famData.dob          = item.dob;
                            famData.createdBy    = User.Identity.Name;
                            famData.createdDate  = DateTime.Now;
                            dbcontext.familyDetail.Add(famData);
                        }
                        //educaton
                        //
                        foreach (var item in empdata.Experiences)
                        {
                            experience exp = new experience()
                            {
                                employeeId     = newEmpData.id,
                                nameOfEmployer = item.nameOfEmployer,
                                empStatus      = item.empStatus,
                                durationFrom   = item.durationFrom,
                                durationTo     = item.durationTo,
                                tenure         = item.tenure,
                                status         = true,
                                createdBy      = User.Identity.Name,
                                createdDate    = DateTime.Now
                            };
                            dbcontext.experience.Add(exp);
                        }
                        dbcontext.SaveChanges();

                        //bool isCreated = this._userProfileService.CreateUserProfile(userprofiles);
                        return(RedirectToAction("Index"));
                    }

                    else //update section
                    {
                        employee previousRecord = dbcontext.employee.Where(a => a.id == empdata.id).FirstOrDefault();
                        //UserProfile previousRecord = this._userProfileService.GetUserProfileById(userprofiles.Id);
                        //check new file selected or not
                        if (photo != null && photo.ContentLength > 0)
                        {
                            string photosavingpath = Server.MapPath("~/UserImage/");
                            //delete old one
                            if (!string.IsNullOrEmpty(previousRecord.photo) && Directory.Exists(photosavingpath))
                            {
                                string fullphotopath = photosavingpath + previousRecord.photo;
                                System.IO.File.Delete(fullphotopath);
                            }
                            //save file
                            string[] imageName = photo.FileName.Split('.').ToArray();
                            string   extension = imageName[(imageName.Length - 1)].ToString();
                            string   fileName  = DateTime.Now.ToString("yyMMddmmhhss") + "_" + photo.FileName + "." + extension;
                            string   filePath  = Path.Combine(photosavingpath, fileName);
                            photo.SaveAs(filePath); //saving photo
                            previousRecord.photo = fileName;
                        }
                        previousRecord.modifiedBy   = empdata.modifiedBy + ";" + User.Identity.Name;
                        previousRecord.modifiedDate = empdata.modifiedDate + ";" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                        dbcontext.Entry <employee>(previousRecord).State = EntityState.Modified;
                        //for family detail table
                        foreach (var fd in empdata.FamilyDetails)
                        {
                            familyDetail prevFamilyDetail = new familyDetail();
                            prevFamilyDetail              = dbcontext.familyDetail.Find(fd.id);
                            prevFamilyDetail.name         = fd.name;
                            prevFamilyDetail.relationship = fd.relationship;
                            prevFamilyDetail.occupation   = fd.occupation;
                            prevFamilyDetail.dob          = fd.dob;
                            dbcontext.Entry <familyDetail>(prevFamilyDetail).State = EntityState.Modified;
                        }

                        //for experience table
                        //first delete previous recorded experiences, then add current
                        List <experience> prevExperiences = dbcontext.experience.Where(a => a.employeeId == empdata.id).ToList();
                        dbcontext.experience.RemoveRange(prevExperiences);

                        foreach (var item in empdata.Experiences)
                        {
                            experience exp = new experience()
                            {
                                employeeId     = empdata.id,
                                nameOfEmployer = item.nameOfEmployer,
                                empStatus      = item.empStatus,
                                durationFrom   = item.durationFrom,
                                durationTo     = item.durationTo,
                                tenure         = item.tenure,
                                status         = true,
                                createdBy      = User.Identity.Name,
                                createdDate    = DateTime.Now
                            };
                            dbcontext.experience.Add(exp);
                        }

                        dbcontext.SaveChanges();

                        //bool isUpdated = this._userProfileService.UpdateUserProfile(userprofiles);
                        return(RedirectToAction("Index"));
                    }
                }
                //List<Province> provinceList = this._provinceServices.GetAllProvinces();
                //ViewBag.Province = new SelectList(provinceList, "Id", "Name");
                return(View(empdata));
            }
            catch (Exception ex)
            {
                throw;
            }
        }