Beispiel #1
0
        public IActionResult Edit(EditInternBindingModel bm, int id)
        {
            var intern = InternServices.GetInternById(id);

            if (!ModelState.IsValid)
            {
                var comapnies = CompanyServices.GetAllCompanies();

                var internDto = new EditInternDto()
                {
                    Intern    = intern,
                    Companies = comapnies
                };

                return(this.View(internDto));
            }

            EditIntern(bm, intern);

            this.InternServices.UpdateIntern(intern);
            var companies = this.CompanyServices.GetAllCompanies();

            intern = InternServices.GetInternById(id);

            var dto = new EditInternDto()
            {
                Intern    = intern,
                Companies = companies
            };

            this.ViewData["edit"] = "You have successfully edited this intern!";

            return(this.View(dto));
        }
Beispiel #2
0
 public InternsController(
     InternServices internServices,
     CompanyServices companyServices,
     IMapper mapper)
 {
     this.InternServices  = internServices;
     this.CompanyServices = companyServices;
     this.Mapper          = mapper;
 }
Beispiel #3
0
        public IActionResult Delete(int id, string slug)
        {
            var intern = InternServices.GetInternById(id);

            if (intern == null || intern.Name != slug)
            {
                return(NotFound());
            }

            return(this.View(intern));
        }
Beispiel #4
0
        public void RemoveIntern()
        {
            var options = new DbContextOptionsBuilder <CompanyRegisterDbContext>()
                          .UseInMemoryDatabase(databaseName: "Add_writes_to_database")
                          .Options;

            var internServices  = new InternServices(new CompanyRegisterDbContext(options));
            var companyServices = new CompanyServices(new CompanyRegisterDbContext(options));

            var company = new Company()
            {
                Id         = 1,
                Name       = "Apple",
                PictureUrl = "https://upload.wikimedia.org/wikipedia/commons/thumb/f/fa/Apple_logo_black.svg/160px-Apple_logo_black.svg.png"
            };

            companyServices.AddToDatabase(company);

            var intern = new Intern()
            {
                Id         = 1,
                CompanyId  = 1,
                Name       = "Veselin",
                PictureUrl =
                    "https://images-eu.ssl-images-amazon.com/images/G/31/img16/imports/AGS/MensFashion_Cat_Clothing._V279132526_.jpg",
                Salary           = 1400,
                DaysOfInternship = 15,
                StartDate        = DateTime.Now
            };

            var secondIntern = new Intern()
            {
                Id         = 2,
                CompanyId  = 1,
                Name       = "Pesho",
                PictureUrl =
                    "https://images-eu.ssl-images-amazon.com/images/G/31/img16/imports/AGS/MensFashion_Cat_Clothing._V279132526_.jpg",
                Salary           = 1400,
                DaysOfInternship = 15,
                StartDate        = DateTime.Now
            };

            internServices.AddIntern(intern);
            internServices.AddIntern(secondIntern);
            internServices.RemoveIntern(intern);

            var result = internServices.GetAllInterns();

            if (result.Count != 1)
            {
                Assert.Fail();
            }
        }
Beispiel #5
0
        public IActionResult FinalDelete(int id, string slug)
        {
            var intern = InternServices.GetInternById(id);

            if (intern == null || intern.Name != slug)
            {
                return(NotFound());
            }

            var dto = new FinalDeleteNameDTO()
            {
                Name = intern.Name
            };

            this.InternServices.RemoveIntern(intern);

            return(this.View(dto));
        }
Beispiel #6
0
        public IActionResult Edit(int id, string slug)
        {
            var intern    = InternServices.GetInternById(id);
            var comapnies = CompanyServices.GetAllCompanies();

            if (intern == null || intern.Name != slug)
            {
                return(NotFound());
            }

            var internDto = new EditInternDto()
            {
                Intern    = intern,
                Companies = comapnies
            };

            return(this.View(internDto));
        }
Beispiel #7
0
        public IActionResult All()
        {
            var interns = InternServices.GetAllInterns();

            return(this.View(interns));
        }
Beispiel #8
0
        public IActionResult Index()
        {
            var interns = InternServices.GetLastThreeInterns();

            return(View(interns));
        }