Beispiel #1
0
        public async Task <IActionResult> Create(EmployeeInfoViewModel employee)
        {
            if (ModelState.IsValid)
            {
                List <Document> teaList = new List <Document>();

                if (employee.DocumentProfile != null)
                {
                    foreach (IFormFile photo in employee.DocumentProfile)
                    {
                        var path   = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images", photo.FileName);
                        var stream = new FileStream(path, FileMode.Create);
                        photo.CopyTo(stream);
                        Document teas = new Document()
                        {
                            DocumentImagePath = photo.FileName
                        };
                        teaList.Add(teas);
                    }
                }
                ;


                if (employee.EmployeeProfile != null)
                {
                    foreach (IFormFile photos in employee.EmployeeProfile)
                    {
                        var path   = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images", photos.FileName);
                        var stream = new FileStream(path, FileMode.Create);
                        photos.CopyTo(stream);
                        EmployeeInfo str = new EmployeeInfo()
                        {
                            EmployeeName    = employee.EmployeeName,
                            FatherName      = employee.FatherName,
                            NRC             = employee.NRC,
                            Nationality     = employee.Nationality,
                            Gender          = employee.Gender,
                            MartialStatus   = employee.MartialStatus,
                            MobilePhone     = employee.MobilePhone,
                            DateOfBirth     = employee.DateOfBirth,
                            CurrentAddress  = employee.CurrentAddress,
                            EmergencyNo     = employee.EmergencyNo,
                            AccountNo       = employee.AccountNo,
                            ATMNumber       = employee.ATMNumber,
                            IsActive        = employee.IsActive,
                            CreatedDate     = employee.CreatedDate,
                            CreatedBy       = employee.CreatedBy,
                            EmployeeProfile = photos.FileName,
                            Document        = teaList,
                            DepartmentId    = employee.DepartmentId,
                            DesignationId   = employee.DesignationId,
                            BranchId        = employee.BranchId
                        };
                        await employeeInfoRepository.Save(str);
                    }
                    return(RedirectToAction(nameof(Index)));
                }
            }

            ViewData["BranchId"]      = new SelectList(branchRepository.GetBranchList(), "Id", "Id", employee.BranchId);
            ViewData["DepartmentId"]  = new SelectList(departmentRepository.GetDepartmentList(), "Id", "Id", employee.DepartmentId);
            ViewData["DesignationId"] = new SelectList(designationRepository.GetDesignationList(), "Id", "Id", employee.DesignationId);
            return(View(employee));
        }
Beispiel #2
0
        public async Task <IActionResult> Create(EmployeeInfoViewModel employee)
        {
            if (ModelState.IsValid)
            {
                var             userId  = httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
                List <Document> teaList = new List <Document>();

                if (employee.DocumentProfile != null)
                {
                    foreach (IFormFile photo in employee.DocumentProfile)
                    {
                        var path   = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/Document", photo.FileName);
                        var stream = new FileStream(path, FileMode.Create);
                        photo.CopyTo(stream);
                        Document teas = new Document()
                        {
                            DocumentImagePath = "../images/Document/" + photo.FileName
                        };
                        teaList.Add(teas);
                    }
                }
                ;



                EmployeeInfo str = new EmployeeInfo()
                {
                    EmployeeName   = employee.EmployeeName,
                    FatherName     = employee.FatherName,
                    NRC            = employee.NRC,
                    Nationality    = employee.Nationality,
                    Gender         = employee.Gender,
                    MartialStatus  = employee.MartialStatus,
                    MobilePhone    = employee.MobilePhone,
                    DateOfBirth    = employee.DateOfBirth,
                    CurrentAddress = employee.CurrentAddress,
                    EmergencyNo    = employee.EmergencyNo,
                    AccountNo      = employee.AccountNo,
                    ATMNumber      = employee.ATMNumber,
                    IsActive       = employee.IsActive,
                    CreatedDate    = DateTime.Now,
                    CreatedBy      = userId,
                    UserId         = userId,
                    Document       = teaList,
                    DepartmentId   = employee.DepartmentId,
                    DesignationId  = employee.DesignationId,
                    BranchId       = employee.BranchId,
                    BasicSalary    = employee.BasicSalary
                };
                if (employee.EmployeeProfile != null)
                {
                    var path   = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images", employee.EmployeeProfile.FileName);
                    var stream = new FileStream(path, FileMode.Create);
                    employee.EmployeeProfile.CopyTo(stream);

                    str.EmployeeProfile = "../images/" + employee.EmployeeProfile.FileName;
                }
                await employeeInfoRepository.Save(str);

                return(RedirectToAction(nameof(Index)));
            }



            ViewData["BranchId"]      = new SelectList(branchRepository.GetBranchList(), "Id", "Id", employee.BranchId);
            ViewData["DepartmentId"]  = new SelectList(departmentRepository.GetDepartmentList(), "Id", "Id", employee.DepartmentId);
            ViewData["DesignationId"] = new SelectList(designationRepository.GetDesignationList(), "Id", "Id", employee.DesignationId);
            return(View(employee));
        }