Beispiel #1
0
        public IActionResult AddEmployee(Employee_WorkPlaceModel employee_WorkPlaceModel, IFormFile file)
        {
            string FilePath = Path.Combine(environment.ContentRootPath, "Images");

            string fileFormat = file.FileName.Substring(file.FileName.LastIndexOf(".") + 1);

            string FileName = employee_WorkPlaceModel.Employee.Name + "_" + employee_WorkPlaceModel.Employee.Surname + "." + fileFormat;

            string FullPath = Path.Combine(FilePath, FileName);

            using (var stream = new FileStream(FullPath, FileMode.OpenOrCreate))
            {
                file.CopyTo(stream);
            }

            employee_WorkPlaceModel.Employee.Photo = FileName;


            context.Employees.Add(employee_WorkPlaceModel.Employee);
            context.SaveChanges();

            employee_WorkPlaceModel.WorkPlace.EmployeeId = employee_WorkPlaceModel.Employee.Id;

            context.WorkPlaces.Add(employee_WorkPlaceModel.WorkPlace);
            context.SaveChanges();

            return(View());
        }
Beispiel #2
0
        public async Task <IActionResult> Create(Employee_WorkPlaceModel employee_workplace, IFormFile file)
        {
            string FilePath = Path.Combine(environment.ContentRootPath, "Images");

            string fileFormat = file.FileName.Substring(file.FileName.LastIndexOf(".") + 1);

            string FileName = employee_workplace.Employee.Name + "_" + employee_workplace.Employee.Surname + "." + fileFormat;

            string FullPath = Path.Combine(FilePath, FileName);

            using (var stream = new FileStream(FullPath, FileMode.OpenOrCreate))
            {
                file.CopyTo(stream);
            }

            employee_workplace.Employee.Photo = FileName;

            await context.Employees.AddAsync(employee_workplace.Employee);

            await context.SaveChangesAsync();

            employee_workplace.WorkPlace.EmployeeId = employee_workplace.Employee.Id;

            await context.WorkPlaces.AddAsync(employee_workplace.WorkPlace);

            await context.SaveChangesAsync();

            return(RedirectToAction("List", "Employee"));
        }