Esempio n. 1
0
        public string Execute(string[] parameters)
        {
            StringBuilder sb = new StringBuilder();

            int managerId = int.Parse(parameters[0]);

            Emoloyee manager = this.context
                               .Emoloyees
                               .Include(e => e.ManagedEmployees)
                               .FirstOrDefault(x => x.Id == managerId);

            ManagerDTO managerDto = this.mapper.CreateMappedObject <ManagerDTO>(manager);

            if (manager == null)
            {
                throw new ArgumentNullException($"Manager with id {managerId} does not exist.");
            }

            sb.AppendLine($"{managerDto.FirstName} {managerDto.LastName} | Employees: {managerDto.ManagedEmployees.Count}");

            foreach (var empl in managerDto.ManagedEmployees)
            {
                sb.AppendLine($"  - {empl.FirstName} {empl.LastName} - ${empl.Salary:f2}");
            }

            return(sb.ToString());
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Emoloyee emoloyee = db.Emoloyees.Find(id);

            db.Emoloyees.Remove(emoloyee);
            db.SaveChanges();
            return(RedirectToAction("SelectSQL"));
        }
 public ActionResult Edit([Bind(Include = "ID,Name,Gender,Birthday")] Emoloyee emoloyee)
 {
     if (ModelState.IsValid)
     {
         db.Entry(emoloyee).State = EntityState.Modified;
         db.SaveChanges();
     }
     return(RedirectToAction("SelectSQL"));
 }
 public ActionResult Create([Bind(Include = "ID,Name,Gender,Birthday")] Emoloyee emoloyee)
 {
     if (ModelState.IsValid)
     {
         db.Emoloyees.Add(emoloyee);
         db.SaveChanges();
     }
     return(RedirectToAction("SelectSQL"));
 }
        // GET: Emoloyees/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Emoloyee emoloyee = db.Emoloyees.Find(id);

            if (emoloyee == null)
            {
                return(HttpNotFound());
            }
            return(View(emoloyee));
        }
Esempio n. 6
0
        public string Execute(string[] parameters)
        {
            StringBuilder stringBuilder = new StringBuilder();

            int      targetingId = int.Parse(parameters[0]);
            Emoloyee employee    = this.context.Emoloyees.Find(targetingId);

            EmployeeInfoDTO dto = mapper.CreateMappedObject <EmployeeInfoDTO>(employee);

            stringBuilder.AppendLine($"ID: {dto.Id} - {dto.FirstName}{dto.LastName} - ${dto.Salary}");
            stringBuilder.AppendLine($@"Birthday: {dto.Birthday.Value.ToString("dd-MM-yyyy")}");
            stringBuilder.AppendLine($"Address: {dto.Address}");

            return(stringBuilder.ToString());
        }
        public string Execute(string[] parameters)
        {
            int      targetingId = int.Parse(parameters[0]);
            DateTime birthday    = DateTime.ParseExact(parameters[1], "dd-MM-yyyy", CultureInfo.InvariantCulture);

            Emoloyee emoloyee = this.context.Emoloyees.Find(targetingId);

            if (emoloyee == null)
            {
                throw new ArgumentNullException($"Employee with id {targetingId} does not exist.");
            }

            emoloyee.Birthday = birthday;
            this.context.SaveChanges();

            SetBirthdayEmployeeDTO employeeDTO = this.mapper.CreateMappedObject <SetBirthdayEmployeeDTO>(emoloyee);

            return($"{employeeDTO.FirstName} {employeeDTO.LastName}'s birth date was set to {employeeDTO.Birthday.Value.ToString("dd-MM-yyyy")}");
        }
        public string Execute(string[] parameters)
        {
            int employeeId = int.Parse(parameters[0]);
            int managerId  = int.Parse(parameters[1]);

            Emoloyee employee = this.context.Emoloyees.Find(employeeId);
            Emoloyee manager  = this.context.Emoloyees.Find(managerId);

            if (employee == null || manager == null)
            {
                throw new ArgumentNullException($"There is not such an employee in the database.");
            }

            employee.Manager = manager;
            this.context.SaveChanges();

            return($@"{employee.FirstName} {employee.LastName}'s manager is 
                      {manager.FirstName} {manager.LastName}");
        }
Esempio n. 9
0
        public string Execute(string[] parameters)
        {
            int    targetingId = int.Parse(parameters[0]);
            string address     = string.Join(" ", parameters.Skip(1));

            Emoloyee employee = this.context.Emoloyees.Find(targetingId);

            if (employee == null)
            {
                throw new ArgumentNullException($"Employee with id {targetingId} does not exist.");
            }

            employee.Address = address;
            this.context.SaveChanges();

            EmployeeAddressDTO employeeDTO = this.mapper.CreateMappedObject <EmployeeAddressDTO>(employee);

            return($"{employeeDTO.FirstName} {employeeDTO.LastName}'s adress was set to {employeeDTO.Address} successfuly.");
        }
Esempio n. 10
0
        public string Execute(string[] parameters)
        {
            string  firstName = parameters[0];
            string  lastName  = parameters[1];
            decimal salary    = decimal.Parse(parameters[2]);

            Emoloyee employee = new Emoloyee()
            {
                FirstName = firstName,
                LastName  = lastName,
                Salary    = salary
            };

            this.context.Add(employee);
            this.context.SaveChanges();

            AddEmployeeDTO employeeDTO = this.mapper.CreateMappedObject <AddEmployeeDTO>(employee);

            return($"Successfully added {employeeDTO.FirstName} {employeeDTO.LastName}");
        }