예제 #1
0
        public ActionResult Edit(Employee employee)
        {
            try
            {
                ViewBag.Updated = false;
                if (employee == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
                }
                EmployeePersonalInfoDTO emp = new EmployeePersonalInfoDTO()
                {
                    EmployeeId      = employee.EmployeeId,
                    Country         = employee.Country,
                    City            = employee.City,
                    PostalCode      = employee.PostalCode,
                    StreetAddress   = employee.StreetAddress,
                    CellPhoneNumber = employee.CellPhoneNumber,
                    WorkPhoneNumber = employee.WorkPhoneNumber,
                    Province        = employee.Province
                };

                emp.TimeStamp = (byte[])Session["TimeStamp"];
                if (employeeService.UpdatePersonalInfo(emp))
                {
                    ViewBag.Updated = true;
                    return(View(employee));
                }
                return(View(employee));
            }
            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Employee", "Index")));
            }
        }
예제 #2
0
        public bool UpdatePersonalInfo(EmployeePersonalInfoDTO employee)
        {
            /*UpdatePersonalInfo*/
            List <ParmStruct> parms = new List <ParmStruct>();

            parms.Add(new ParmStruct("@Timestamp", employee.TimeStamp, SqlDbType.Timestamp, ParameterDirection.InputOutput));
            parms.Add(new ParmStruct("@EmployeeId", employee.EmployeeId, SqlDbType.Int, ParameterDirection.Input));
            parms.Add(new ParmStruct("@StreetAddress", employee.StreetAddress, SqlDbType.NVarChar, ParameterDirection.Input, 200));
            parms.Add(new ParmStruct("@Country", employee.Country, SqlDbType.NVarChar, ParameterDirection.Input, 50));
            parms.Add(new ParmStruct("@Province", employee.Province, SqlDbType.NVarChar, ParameterDirection.Input, 50));
            parms.Add(new ParmStruct("@City", employee.City, SqlDbType.NVarChar, ParameterDirection.Input, 255));
            parms.Add(new ParmStruct("@PostalCode", employee.PostalCode, SqlDbType.NVarChar, ParameterDirection.Input, 7));
            parms.Add(new ParmStruct("@WorkPhoneNumber", employee.WorkPhoneNumber, SqlDbType.NVarChar, ParameterDirection.Input, 15));
            parms.Add(new ParmStruct("@CellPhoneNumber", employee.CellPhoneNumber, SqlDbType.NVarChar, ParameterDirection.Input, 15));


            DataAccess db           = new DataAccess();
            bool       isSupervisor = false;

            if (db.ExecuteNonQuery("UpdatePersonalInfo", CommandType.StoredProcedure, parms) > 0)
            {
                employee.TimeStamp = (byte[])parms[0].Value;
                return(true);
            }
            return(false);
        }
        public EmployeePersonalInfoDTO PersonalInfoById(int employeeId)
        {
            Employee employee = context.Employees.Find(employeeId);

            EmployeePersonalInfoDTO employeePersonalInfo = Mapper.Map <EmployeePersonalInfoDTO>(employee);

            return(employeePersonalInfo);
        }
예제 #4
0
        public bool UpdatePersonalInfo(EmployeePersonalInfoDTO employee)
        {
            if (employeeRepository.HasBeenUpdated(employee))
            {
                employee.AddError(new Error(employee.Errors.Count() + 1, "This employee record has been updated after you retrieved it. Please reload before updated", "Business"));
            }

            return(IsValid(employee) ? employeeRepository.UpdatePersonalInfo(employee) : false);
        }
        // <employeeId>
        public string Execute(params string[] args)
        {
            int employeeId = int.Parse(args[0]);

            EmployeePersonalInfoDTO employeeInfoDto = employeeService.PersonalInfoById(employeeId);

            string birthdayOutput = employeeInfoDto.Birthday.HasValue ? employeeInfoDto.Birthday.Value.ToString("dd-MM-yyyy", CultureInfo.InvariantCulture) : "No birthday entered";

            string result = $"ID: {employeeInfoDto.Id} - {employeeInfoDto.FirstName} {employeeInfoDto.LastName} - ${employeeInfoDto.Salary:f2}" + Environment.NewLine +
                            $"Birthday: {birthdayOutput}" + Environment.NewLine +
                            $"Address: {employeeInfoDto.Address ?? "No address entered"}";

            return(result);
        }
예제 #6
0
        private bool IsValidEntity(EmployeePersonalInfoDTO employee)
        {
            ValidationContext       context = new ValidationContext(employee);
            List <ValidationResult> results = new List <ValidationResult>();

            bool isValid = Validator.TryValidateObject(employee, context, results, true);

            foreach (ValidationResult r in results)
            {
                employee.AddError(new Error(employee.Errors.Count + 1, r.ErrorMessage, "Model"));
            }

            return(isValid);
        }
예제 #7
0
        public bool HasBeenUpdated(EmployeePersonalInfoDTO employee)
        {
            byte[] timestamp = (byte[])new DataAccess().ExecuteScaler($"SELECT Timestamp From employee WHERE EmployeeID = {employee.EmployeeId}", CommandType.Text);

            for (int i = 0; i < timestamp.Length; i++)
            {
                if (timestamp[i] != employee.TimeStamp[i])
                {
                    return(true);
                }
            }

            return(false);
        }
        public IActionResult Put(int id, [FromBody] EmployeePersonalInfoDTO modifiedEmployee)
        {
            try
            {
                using (NorthwindContext dbContext = new())
                {
                    EmployeeSC.UpdateEmployee(dbContext, id, modifiedEmployee);
                }

                return(Ok());
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
        public IActionResult Post([FromBody] EmployeePersonalInfoDTO newEmployee)
        {
            int id;

            try
            {
                using (NorthwindContext dbContext = new())
                {
                    id = EmployeeSC.AddNewEmployee(dbContext, newEmployee);
                }

                return(Ok("Registered Id: " + id));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
예제 #10
0
 public bool IsValid(EmployeePersonalInfoDTO employee)
 {
     return(IsValidEntity(employee) && employee.Errors.Count == 0);
 }