public async Task <string> AddUpdateUser(EmployeeVM employeeVM)
        {
            EmployeeDomainModel employeeDM = new EmployeeDomainModel();

            AutoMapper.Mapper.Map(employeeVM, employeeDM);
            return(await employeeBusiness.AddUpdateEmployee(employeeDM));
        }
        public EmployeeDomainModel AddEditEmployee(EmployeeDomainModel domainModel)
        {
            if (domainModel.EmployeeId > 0)
            {
                //update
                Employee employee = empRepository.SingleOrDefault(x => x.EmployeeId == domainModel.EmployeeId && x.IsDeleted == false);

                employee.DepartmentId = domainModel.DepartmentId;
                employee.Name         = domainModel.Name;
                employee.Address      = domainModel.Address;
                empRepository.Update(employee);
            }
            else
            {
                //Insert
                Employee employee = new Employee();
                employee.Address      = domainModel.Address;
                employee.Name         = domainModel.Name;
                employee.DepartmentId = domainModel.DepartmentId;
                employee.IsDeleted    = false;
                empRepository.Insert(employee);

                domainModel.EmployeeId = employee.EmployeeId;
            }

            return(domainModel);
        }
Esempio n. 3
0
 public HttpResponseMessage GetEmployeeDataById(long UserId)
 {
     try
     {
         HttpResponseMessage httpResponse = new HttpResponseMessage();
         EmployeeDomainModel objRes       = new EmployeeDomainModel();
         objRes = managementRepository.GetEmployeeDataById(UserId);
         if (objRes != null)
         {
             httpResponse = Request.CreateResponse(HttpStatusCode.OK, objRes);
         }
         else
         {
             httpResponse = Request.CreateResponse(HttpStatusCode.Unauthorized, objRes);
         }
         return(httpResponse);
     }
     catch (Exception ex)
     {
         throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
         {
             Content      = new StringContent("An error occurred, please try again or contact the administrator."),
             ReasonPhrase = "An error occurred, please try again or contact the administrator.",
             StatusCode   = HttpStatusCode.InternalServerError
         });
     }
 }
Esempio n. 4
0
 public HttpResponseMessage AddUpdateEmployee(EmployeeDomainModel model)
 {
     try
     {
         HttpResponseMessage httpResponse = new HttpResponseMessage();
         var res = managementRepository.AddUpdateEmployee(model);
         if (res != null && res.isSuccess)
         {
             httpResponse = Request.CreateResponse(HttpStatusCode.OK, res);
         }
         else
         {
             httpResponse = Request.CreateResponse(HttpStatusCode.Unauthorized, res);
         }
         return(httpResponse);
     }
     catch (Exception ex)
     {
         ErrorLog.LogError(ex);
         throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
         {
             Content      = new StringContent("An error occurred, please try again or contact the administrator."),
             ReasonPhrase = "An error occurred, please try again or contact the administrator.",
             StatusCode   = HttpStatusCode.InternalServerError
         });
     }
 }
        public IHttpActionResult Put(short id, EmployeeDomainModel employee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != employee.EMPLOYEE_ID)
            {
                return(BadRequest());
            }

            try
            {
                db.PutSingleEmployee(employee);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!db.EmployeeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        /// <summary>
        /// Get Employees for Id provided.
        /// </summary>
        /// <param name="employeeid">employeeid</param>
        /// <returns>EmployeeDomainModel object; otherwise, Exception.</returns>
        public EmployeeDomainModel SelectEmployeesById(int employeeid)
        {
            // intercept the data from the DAL
            EmployeeDomainModel employee = HideHomePhone(DAL.SelectEmployeesById(employeeid));

            return(employee);
        }
Esempio n. 7
0
        public void DataToDomaonModelMustMatch()
        {
            var timeStamp = DateTime.Now;

            var sourceDataModel = new Employee()
            {
                ID         = 1,
                Created    = timeStamp,
                RowVersion = "rowversion",
                FirstName  = "John",
                LastName   = "Smith",
                Department = null
            };

            var expectedDomainModel = new EmployeeDomainModel()
            {
                ID         = 1,
                Created    = timeStamp,
                RowVersion = "rowversion",
                FirstName  = "John",
                LastName   = "Smith",
            };

            var mappedDomainModel = _mapper.Map <IEmployeeDomainModel>(sourceDataModel);

            mappedDomainModel.Should().BeEquivalentTo(expectedDomainModel);
        }
        public string AddUpdateEmployee(EmployeeDomainModel empModel)
        {
            string result = "";

            if (empModel.EmployeeId > 0)
            {
                Employee emp = empRepository.SingleOrDefault(x => x.EmployeeId == empModel.EmployeeId);

                if (emp != null)
                {
                    emp.Name         = empModel.Name;
                    emp.DepartmentId = empModel.DepartmentId;
                    emp.Address      = empModel.Address;

                    empRepository.Update(emp);

                    result = "updated";
                }
            }
            else
            {
                Employee emp = new Employee();

                emp.Name         = empModel.Name;
                emp.DepartmentId = empModel.DepartmentId;
                emp.Address      = empModel.Address;
                emp.IsDeleted    = false;

                var record = empRepository.Insert(emp);

                result = "Inserted";
            }

            return(result);
        }
        public async Task <IActionResult> UpdateAsync(Guid id, [FromBody] EmployeeDomainModel model)
        {
            if (model == null || model.EmployeeId != id)
            {
                return(BadRequest("The model that is passed in is empty. Model object is required."));
            }

            EmployeeDomainModel selected;

            try
            {
                selected = await _domain.GetAsync(id).ConfigureAwait(false);

                if (selected == null)
                {
                    return(NotFound("The asset category selected to be updated could not be found."));
                }
            }
            catch (Exception ex) { return(BadRequest(ex.InnerException)); }

            selected.FirstName    = model.FirstName;
            selected.LastName     = model.LastName;
            selected.ModifiedDate = DateTime.UtcNow;

            try { await _domain.UpdateAsync(selected).ConfigureAwait(false); }
            catch (Exception ex) { return(BadRequest(ex.InnerException)); }

            return(Ok(selected));
        }
        public async Task <EmployeeToReturnVM> GetEmployeeById(int id)
        {
            EmployeeToReturnVM  employeeToReturnVM  = new EmployeeToReturnVM();
            EmployeeDomainModel employeeDomainModel = await employeeBusiness.GetEmployeeById(id);

            AutoMapper.Mapper.Map(employeeDomainModel, employeeToReturnVM);
            return(employeeToReturnVM);
        }
 /// <summary>
 /// Insert a new employee record into the Northwind database.
 /// </summary>
 /// <param name="employee">Employee object</param>
 /// <returns>int; otherwise, Exception.</returns>
 public int InsertEmployee(EmployeeDomainModel employee)
 {
     // Create a context object wrapped in a using statement.
     using (NorthwindEntities northwindConnection = new NorthwindEntities())
     {
         return(northwindConnection.InsertEmployee(employee.LastName, employee.FirstName, employee.Title, employee.HomePhone));
     }
 }
 /// <summary>
 /// Hide Home Phone Number Business Rule
 /// </summary>
 /// <param name="obj">EmployeeDomainModel object</param>
 /// <returns>EmployeeDomainModel object; otherwise, Exception.</returns>
 private EmployeeDomainModel HideHomePhone(EmployeeDomainModel obj)
 {
     // apply a business rule.
     if (obj.Title.Contains("Manager"))
     {
         obj.HomePhone = "Not Available";
     }
     return(obj);
 }
        public void PutSingleEmployee(EmployeeDomainModel employee)
        {
            //db.Entry(employee).State = EntityState.Modified;
            EMPLOYEE emp = db.EMPLOYEEs.SingleOrDefault(t => t.EMPLOYEE_ID == employee.EMPLOYEE_ID);

            emp.EMPLOYEE_NAME       = employee.EMPLOYEE_NAME;
            emp.EMPLOYEE_SALARY     = employee.EMPLOYEE_SALARY;
            emp.EMPLOYEE_DEPARTMENT = employee.EMPLOYEE_DEPARTMENT;
            db.SaveChanges();
        }
Esempio n. 14
0
 /// <summary>
 ///  Convert From EmployeeDomainModel To Employee
 /// </summary>
 /// <param name="obj"></param>
 /// <returns></returns>
 public static Employee Map(EmployeeDomainModel obj)
 {
     return(new Employee
     {
         EmployeeId = obj.EmployeeId,
         FirstName = obj.FirstName,
         HomePhone = obj.HomePhone,
         LastName = obj.LastName,
         Title = obj.Title
     });
 }
        public EmployeeDomainModel GetSingleEmployee(int empID)
        {
            EmployeeDomainModel single = db.EMPLOYEEs.Where(t => t.EMPLOYEE_ID == empID).Select(t => new EmployeeDomainModel
            {
                EMPLOYEE_ID         = t.EMPLOYEE_ID,
                EMPLOYEE_NAME       = t.EMPLOYEE_NAME,
                EMPLOYEE_SALARY     = t.EMPLOYEE_SALARY,
                EMPLOYEE_DEPARTMENT = t.EMPLOYEE_DEPARTMENT
            }).First();

            return(single);
        }
        public async Task <IActionResult> DeleteAsync(Guid id)
        {
            if (id == Guid.Empty)
            {
                return(BadRequest());
            }

            EmployeeDomainModel deleted = null;

            try { deleted = await _domain.DeleteAsync(id).ConfigureAwait(false); }
            catch (Exception ex) { return(BadRequest(ex.InnerException)); }

            return(Ok(deleted));
        }
        public async Task <IActionResult> CreateAsync([FromBody] EmployeeDomainModel model)
        {
            if (model == null)
            {
                return(BadRequest("The model that is passed in is empty. Model object is required."));
            }

            EmployeeDomainModel inserted;

            try { inserted = await _domain.InsertAsync(model).ConfigureAwait(false); }
            catch (Exception ex) { return(BadRequest(ex.InnerException)); }

            return(CreatedAtRoute("GetEmployee", new { id = inserted.EmployeeId }, inserted));
        }
        public EmployeeDomainModel GetEmployeeById(int Id)
        {
            EmployeeDomainModel empDomainModel = new EmployeeDomainModel();
            Employee            emp            = empRepository.SingleOrDefault(x => x.EmployeeId == Id && x.IsDeleted == false);

            if (emp != null)
            {
                empDomainModel.EmployeeId   = emp.EmployeeId;
                empDomainModel.DepartmentId = emp.DepartmentId;
                empDomainModel.Name         = emp.Name;
                empDomainModel.Address      = emp.Address;
            }

            return(empDomainModel);
        }
Esempio n. 19
0
        public ActionResult AddEditEmployee(EmployeeViewModel empView)
        {
            string result = "";

            empView.EmpId   = empView.EmpId;
            empView.Name    = empView.Name;
            empView.Address = empView.Address;
            empView.DeptId  = empView.DeptId;
            EmployeeDomainModel empDoModel = new EmployeeDomainModel();

            AutoMapper.Mapper.Map(empView, empDoModel);
            result = _emp.AddEditEmp(empDoModel);

            return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet));
        }
        /// <summary> <see cref="IEmployeeDomain.InsertAsync"/> </summary>
        /// <exception cref="ArgumentNullException"><paramref name="domainModel"/> is <see langword="null"/></exception>
        public async Task <EmployeeDomainModel> InsertAsync(EmployeeDomainModel domainModel)
        {
            if (domainModel == null)
            {
                throw new ArgumentNullException(nameof(domainModel));
            }

            var model = ToModel <Employee, EmployeeDomainModel>(domainModel);

            model = await _repository.InsertAsync(model).ConfigureAwait(false);

            domainModel = ToModel <EmployeeDomainModel, Employee>(model);

            return(domainModel);
        }
        /// <summary>
        /// Called when we click on edit button, it renders employee record by Id using Partial view
        /// </summary>
        /// <param name="EmployeeId"></param>
        /// <returns></returns>
        public ActionResult AddEditEmployee(int EmployeeId)
        {
            List <DepartmentDomainModel> list = departmentBusiness.GetAllDepartment();

            ViewBag.DepartmentList = new SelectList(list, "DepartmentId", "DepartmentName");

            EmployeeViewModel   model          = new EmployeeViewModel();
            EmployeeDomainModel empDomainModel = new EmployeeDomainModel();

            if (EmployeeId > 0)
            {
                empDomainModel = empBusiness.GetEmployeeById(EmployeeId);
                AutoMapper.Mapper.Map(empDomainModel, model);
            }
            return(PartialView("Partial2", model));
        }
Esempio n. 22
0
        public string AddEditEmployee()
        {
            string            result = "";
            EmployeeViewModel vm     = new EmployeeViewModel();

            vm.EmployeeID   = 13;
            vm.Name         = "Shovon";
            vm.Address      = "Khulna";
            vm.DepartmentId = 2;

            EmployeeDomainModel empDomainModel = new EmployeeDomainModel();

            AutoMapper.Mapper.Map(vm, empDomainModel);

            result = empBusiness.AddUpdateEmployee(empDomainModel);
            return(result);
        }
Esempio n. 23
0
        public string AddEditEmployee()
        {
            string            result            = "";
            EmployeeViewModel employeeViewModel = new EmployeeViewModel
            {
                EmployeeID   = 1030,
                Address      = "Comuna 13",
                Name         = "Jose",
                DepartmentId = 1
            };

            EmployeeDomainModel employeeDomainModel = new EmployeeDomainModel();

            AutoMapper.Mapper.Map(employeeViewModel, employeeDomainModel);
            result = _employeeBusiness.AddUpdateEmployee(employeeDomainModel);
            return(result);
        }
Esempio n. 24
0
        public async Task <EmployeeDomainModel> GetEmployeeById(int id)
        {
            EmployeeDomainModel employee = new EmployeeDomainModel();
            var model = await employeeRepository.SingleOrDefault(e => e.emp_id == id);

            if (model != null)
            {
                employee.emp_id  = model.emp_id;
                employee.name    = model.name;
                employee.contact = model.contact;
                employee.address = model.address;
                employee.NIC     = model.NIC;
                employee.salary  = model.salary;
                employee.date    = model.date;
            }
            return(employee);
        }
Esempio n. 25
0
        public string AddEditEmployee()
        {
            string            result = "";
            EmployeeViewModel vm     = new EmployeeViewModel();

            vm.EmployeeId   = 2014;
            vm.Name         = "Laura";
            vm.DepartmentId = 3;
            vm.Address      = "Australia";

            EmployeeDomainModel empDomainModel = new EmployeeDomainModel();

            AutoMapper.Mapper.Map(vm, empDomainModel);

            result = empBusiness.AddUpdateEmployee(empDomainModel);

            return(result);
        }
        private bool CalculateDiscount(EmployeeDomainModel model, string firstName)
        {
            var discountApplied = false;

            model.YearlyWage = 2000 * 26;

            model.TotalDeductions = 1000;
            discountApplied       = firstName.StartsWith('A');
            if (discountApplied)
            {
                var discount = model.YearlyWage / 10;
                model.TotalDeductions = model.TotalDeductions + discount;
            }

            model.FinalWage = model.YearlyWage - model.TotalDeductions;

            return(discountApplied);
        }
        public ActionResult Index(EmployeeViewModel model)
        {
            try
            {
                List <DepartmentDomainModel> list = departmentBusiness.GetAllDepartment();
                ViewBag.DepartmentList = new SelectList(list, "DepartmentId", "DepartmentName");

                EmployeeDomainModel empDomain = new EmployeeDomainModel();
                AutoMapper.Mapper.Map(model, empDomain);

                empDomain = empBusiness.AddEditEmployee(empDomain);

                AutoMapper.Mapper.Map(empDomain, model);

                return(View(model));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 28
0
        public async Task <string> AddUpdateEmployee(EmployeeDomainModel employee)
        {
            string status = "";

            if (employee.emp_id > 0)
            {
                tblEmployee employeeToUpdate = await employeeRepository.SingleOrDefault(e => e.emp_id == employee.emp_id);

                if (employeeToUpdate != null)
                {
                    employeeToUpdate.name    = employee.name;
                    employeeToUpdate.contact = employee.contact;
                    employeeToUpdate.address = employee.address;
                    employeeToUpdate.NIC     = employee.NIC;
                    employeeToUpdate.salary  = employee.salary;
                    employeeToUpdate.date    = employee.date;
                    await employeeRepository.Update(employeeToUpdate);

                    status = "updated";
                }
            }
            else
            {
                tblEmployee employeeToAdd = new tblEmployee();
                employeeToAdd.name    = employee.name;
                employeeToAdd.contact = employee.contact;
                employeeToAdd.address = employee.address;
                employeeToAdd.NIC     = employee.NIC;
                employeeToAdd.salary  = employee.salary;
                employeeToAdd.date    = employee.date;
                await employeeRepository.Insert(employeeToAdd);

                status = "added";
            }
            return(status);
        }
 public int InsertEmployee(EmployeeDomainModel employee)
 {
     return(DAL.InsertEmployee(employee));
 }