public PartialViewResult DeleteIntern(long id)
        {
            var person = PersonRepository.GetItemById <Intern>(id);
            var intern = new InternModel(person);

            return(PartialView(intern));
        }
        public PartialViewResult EditIntern(long id)
        {
            var person    = PersonRepository.GetItemById <Intern>(id);
            var items     = new List <SelectListItem>();
            var companies = CompanyRepository.GetAllCompanyNames();

            //items.Add(new SelectListItem { Text = "No company", Value = "0" });
            foreach (var comp in companies)
            {
                if (comp.CompanyNames == person.Company.CompanyName)
                {
                    items.Add(new SelectListItem {
                        Text = comp.CompanyNames, Value = comp.Id.ToString(), Selected = true
                    });
                }
                else
                {
                    items.Add(new SelectListItem {
                        Text = comp.CompanyNames, Value = comp.Id.ToString()
                    });
                }
            }

            var intern = new InternModel(person);

            intern.Companies = items;
            return(PartialView(intern));
        }
Exemple #3
0
 public IActionResult Register(InternModel i)
 {
     // check empty fields
     if (String.IsNullOrEmpty(i.FirstName) || String.IsNullOrEmpty(i.LastName) || String.IsNullOrEmpty(i.About))
     {
         ViewData["Message"] = "You must complete all fields";
         return(View("Index"));
     }
     // check First, Last name not number or special character
     if (!Regex.IsMatch(i.FirstName, @"^[a-zżźćńółęąśA-ZŻŹĆĄŚĘŁÓŃ]+$") || !Regex.IsMatch(i.LastName, @"^[a-zżźćńółęąśA-ZŻŹĆĄŚĘŁÓŃ]+$"))
     {
         ViewData["Message"] = "You must use only letters to FirstName, LastName fields";
         return(View("Index"));
     }
     // check First, Last name in capital letters
     if (!Regex.IsMatch(i.FirstName, @"^[A-ZŻŹĆĄŚĘŁÓŃ][a-zżźćńółęąś]+$") || !Regex.IsMatch(i.LastName, @"^[A-ZŻŹĆĄŚĘŁÓŃ][a-zżźćńółęąś]+$"))
     {
         ViewData["Message"] = "Name and surname begin with uppercase letters";
         return(View("Index"));
     }
     if (i.FirstName.Length < 3)
     {
         ViewData["Message"] = "Enter the correct data, First Name must be greater than 3";
         return(View("Index"));
     }
     try
     {
         string        connectionString = "Server=localhost\\SQLEXPRESS01;Database=master;Trusted_Connection=True;";
         SqlConnection connection       = new SqlConnection(connectionString);
         connection.Open();
         //SqlCommand cmd = new SqlCommand("CREATE TABLE Interns1 ( ID int NOT NULL IDENTITY (1,1) PRIMARY KEY,LastName varchar(255) NOT NULL, FirstName varchar(255), About varchar(255)); ", connection);
         string     querry = "INSERT INTO Interns1 (LastName,FirstName,About) VALUES (@LastName,@FirstName,@About)";
         SqlCommand cmd    = new SqlCommand(querry, connection);
         cmd.Parameters.AddWithValue("@LastName", i.LastName);
         cmd.Parameters.AddWithValue("@FirstName", i.FirstName);
         cmd.Parameters.AddWithValue("@About", i.About);
         int x = cmd.ExecuteNonQuery();
         if (x < 0)
         {
             ViewData["TotalData"] = "Error inserting data into Database!";
         }
         connection.Close();
         ViewData["Isok"]      = true;
         ViewData["TotalData"] = "Your data has been correctly added to the database";
     }
     catch (Exception ex)
     {
         ViewData["TotalData"] = ex.Message;
     }
     return(View(i));
 }
        public ActionResult CreateIntern(InternModel newintern)
        {
            if (ModelState.IsValid)
            {
                var company = CompanyRepository.GetItemById <Company>(newintern.CompanyId);
                var address = new Address(newintern.Street, newintern.City);
                var skill   = new Dictionary <string, int>();
                var intern  = InternFactory.CreateIntern(newintern.Firstname, newintern.Lastname, newintern.BirthDate,
                                                         skill, address, company, newintern.AverageMark);
                PersonRepository.AddPerson(intern);

                var pers = PersonRepository.GetAllFirstAndLastNames();
                return(PartialView("WorkerList", pers));
            }
            return(PartialView(newintern));
        }
        public ActionResult EditIntern(long id, InternModel editedIntern)
        {
            if (ModelState.IsValid)
            {
                var newIntern = new InternDetailsDto();
                editedIntern.ConvertToDto(newIntern);
                var currentIntern  = PersonRepository.GetItemById <Intern>(id);
                var currentAddress = AddressRepository.GetItemById <Address>(currentIntern.Address.Id);
                AddressRepository.UpdateAddress(currentAddress, editedIntern.City, editedIntern.Street);
                var newCompany = CompanyRepository.GetItemById <Company>(newIntern.CompanyId);
                PersonRepository.UpdateIntern(currentIntern, newIntern, newCompany);

                var pers = PersonRepository.GetAllFirstAndLastNames();
                return(PartialView("WorkerList", pers));
            }
            return(PartialView(editedIntern));
        }
        public PartialViewResult CreateIntern()
        {
            var items     = new List <SelectListItem>();
            var companies = CompanyRepository.GetAllCompanyNames();

            items.Add(new SelectListItem {
                Text = "Select copmany", Value = "0", Selected = true
            });
            foreach (var comp in companies)
            {
                items.Add(new SelectListItem {
                    Text = comp.CompanyNames, Value = comp.Id.ToString()
                });
            }
            var pers = new InternModel(items);

            return(PartialView(pers));
        }
Exemple #7
0
        //[ResponseType(typeof(InternInfo))]
        public IHttpActionResult RegisterInter([FromBody] InternModel model)
        {
            InternInfo info = new InternInfo();

            info.First_Name = model.First_Name;
            info.Last_Name  = model.Last_Name;
            info.College    = model.College;


            int i = internrepo.AddInter(info);

            if (i >= 1)
            {
                return(Ok("Successfully Register"));
            }
            else
            {
                return(BadRequest("Not a valid model"));
            }
        }