public IEnumerable <EmployeeDetails> Put([FromBody] EmployeeUpdate emp)
        {
            if (emp.queryType == "Parant")
            {
                var id = ObjectId.Parse(emp.ParentId);
                int i;
                var filter      = Builders <EmployeeDetails> .Filter;
                var empployeeId = filter.And(
                    filter.Eq(x => x.Id, id));
                var employee    = _EmployeeCollection.Find(empployeeId).SingleOrDefault();
                var updatee     = Builders <EmployeeDetails> .Update;
                var updateValue = new List <UpdateDefinition <EmployeeDetails> >();
                int count       = emp.Field.Count();

                for (i = 0; i < count; i++)
                {
                    updateValue.Add(updatee.Set(emp.Field[i], emp.value[i]));
                    //nameupdate = nameupdate+".Set(\""+emp.Field[i]+"\":\""+emp.value[i]+"\")";
                }
                var update = updatee.Combine(updateValue);
                // System.Diagnostics.Debug.WriteLine(nameupdate);
                _EmployeeCollection.UpdateOne(empployeeId, update);
                return(_EmployeeCollection.Find(x => x.Id == id).ToList());
            }
            else if (emp.queryType == "Child")
            {
                var field   = "x." + emp.queryField;
                var id      = ObjectId.Parse(emp.ParentId);
                var childId = ObjectId.Parse(emp.ChildId);

                var filter = Builders <EmployeeDetails> .Filter;
                var empployeeIdandAddId = filter.And(filter.Eq(x => x.Id, id), filter.ElemMatch(x => x.Address, c => c.Id == childId));

                var employee   = _EmployeeCollection.Find(empployeeIdandAddId).SingleOrDefault();
                var updatee    = Builders <EmployeeDetails> .Update;
                var nameupdate = updatee.Set("Address.$.City", emp.value[0]);
                _EmployeeCollection.UpdateOne(empployeeIdandAddId, nameupdate);
                return(_EmployeeCollection.Find(x => x.Id == id).ToList());
            }

            /*var Id = ObjectId.Parse(id);
             * int i;
             * var filter = Builders<EmployeeDetails>.Filter;
             * var empployeeId = filter.And(
             *  filter.Eq(x => x.Id, Id));
             * var employee = _EmployeeCollection.Find(empployeeId).SingleOrDefault();
             * var updatee = Builders<EmployeeDetails>.Update;
             * var updateValue = new List<UpdateDefinition<EmployeeDetails>>();
             * int count = emp.Field.Count();
             *
             * for (i = 0; i < count; i++)
             * {
             *  updateValue.Add(updatee.Set(emp.Field[i], emp.value[i]));
             *  //nameupdate = nameupdate+".Set(\""+emp.Field[i]+"\":\""+emp.value[i]+"\")";
             * }
             * var update = updatee.Combine(updateValue);
             * // System.Diagnostics.Debug.WriteLine(nameupdate);
             * _EmployeeCollection.UpdateOne(empployeeId, update);*/
            return(_EmployeeCollection.Find(x => x.Id == ObjectId.Parse(emp.ParentId)).ToList());
        }
        private void EmployeeUpdate_Click(object sender, EventArgs e)
        {
            EmployeeUpdate eu = new EmployeeUpdate(emp);

            eu.ShowDialog();
            LoadData();
        }
        public async Task <IActionResult> Update([FromBody] EmployeeUpdate model)
        {
            try
            {
                var result = await _employeeService.Update(model);

                return(Ok(result));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
        public async Task <IActionResult> UpdateEmployee(long id, [FromBody] EmployeeUpdate upd)
        {
            var dbEmployee = await _db.Employees.FirstOrDefaultAsync(x => x.Id == id).ConfigureAwait(false);

            if (dbEmployee == null)
            {
                return(NotFound());
            }

            if (upd.Department != null && dbEmployee.Department != upd.Department)
            {
                dbEmployee.Department = upd.Department;
            }

            if (upd.Name != null && dbEmployee.Name != upd.Name)
            {
                dbEmployee.Name = upd.Name;
            }

            if (upd.DomainNameEntry != null && dbEmployee.DomainNameEntry != upd.DomainNameEntry)
            {
                dbEmployee.DomainNameEntry = upd.DomainNameEntry;
            }

            if (upd.WorkingPosition != null && dbEmployee.WorkingPosition != upd.WorkingPosition)
            {
                dbEmployee.WorkingPosition = upd.WorkingPosition;
            }

            if (upd.PhoneNumber != null && dbEmployee.PhoneNumber != upd.PhoneNumber)
            {
                dbEmployee.PhoneNumber = upd.PhoneNumber;
            }

            if (upd.Email != null && dbEmployee.Email != upd.Email)
            {
                dbEmployee.Email = upd.Email;
            }

            if (upd.Ipv4Address != null && dbEmployee.Ipv4Address != upd.Ipv4Address)
            {
                dbEmployee.Ipv4Address = upd.Ipv4Address;
            }

            _db.Employees.Update(dbEmployee);
            await _db.SaveChangesAsync().ConfigureAwait(false);

            return(Ok(_mapper.Map <EmployeeDt>(dbEmployee)));
        }
        public async Task <ActionResult> Update([FromRoute] int id, [FromBody] EmployeeUpdate request)
        {
            if (ModelState.IsValid)
            {
                var employeeDto = request.ToDto();
                var updated     = await _context.Update(employeeDto, id);

                if (updated is null)
                {
                    return(NotFound());
                }

                return(Ok());
            }

            return(BadRequest("model validation failed"));
        }
Beispiel #6
0
        // Update specific item
        public EmployeeUpdate UpdateEmployee(EmployeeUpdate updatedEmployee)
        {
            var p = ds.Employees.Find(updatedEmployee.Id);

            if (p == null)
            {
                return(null);
            }
            else
            {
                // For the object fetched from the data store,
                // set its values to those provided
                // (the method ignores missing properties, and navigation properties)
                ds.Entry(p).CurrentValues.SetValues(updatedEmployee);
                ds.SaveChanges();
                return(updatedEmployee);
            }
        }
        public async Task <ActionResult> UpdateEmployeeAsync(int id, [FromBody] EmployeeUpdate newEmployeeData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var employee = await _contactService.GetEmployeeAsync(id);

            if (employee is null)
            {
                return(NotFound($"No employee with id '{id}' exists"));
            }

            await _contactService.UpdateEmployeeAsync(id, newEmployeeData);

            return(Ok());
        }
        public ActionResult Update(int id)
        {
            var service = CreateEmployeeService();
            var detail  = service.GetEmployeeById(id);
            var model   =
                new EmployeeUpdate
            {
                EmployeeId   = detail.EmployeeId,
                Name         = detail.Name,
                Address      = detail.Address,
                City         = detail.City,
                State        = detail.State,
                PhoneNumber  = detail.PhoneNumber,
                EmailAddress = detail.EmailAddress
            };

            return(View(model));
        }
Beispiel #9
0
        public void GetXmlTest()
        {
            string expected = @"<?xml version=""1.0"" encoding=""utf-8""?>
<function controlid=""unittest"">
    <update>
        <EMPLOYEE>
            <EMPLOYEEID>E1234</EMPLOYEEID>
        </EMPLOYEE>
    </update>
</function>";

            EmployeeUpdate record = new EmployeeUpdate("unittest")
            {
                EmployeeId = "E1234"
            };

            this.CompareXml(expected, record);
        }
        public Employees_tests()
        {
            _employeeController = new EmployeeController(_IEmployeeRepository.Object);

            _employeeDto = new EmployeeDto()
            {
                Name           = "Gvidas",
                Surname        = "Nor",
                Address        = "Sauletekio ave. 18., Vilnius",
                BirthDate      = DateTime.Now,
                Email          = "*****@*****.**",
                Password       = "******",
                PersonalCode   = "3888888878",
                Phone          = "8655547558",
                EmploymentDate = DateTime.Now.ToString(),
                Id             = 2,
            };

            _employeeCreate = new EmployeeCreate()
            {
                Name           = "Gvidas",
                Surname        = "Nor",
                Address        = "Sauletekio ave. 18., Vilnius",
                BirthDate      = DateTime.Now,
                Email          = "*****@*****.**",
                Password       = "******",
                PersonalCode   = "3888888878",
                Phone          = "8655547558",
                EmploymentDate = DateTime.Now.ToString()
            };

            _employeeUpdate = new EmployeeUpdate()
            {
                Name           = "Gvidas",
                Surname        = "Nor",
                Address        = "Sauletekio ave. 18., Vilnius",
                BirthDate      = DateTime.Now,
                Email          = "*****@*****.**",
                Password       = "******",
                PersonalCode   = "3888888878",
                Phone          = "8655547558",
                EmploymentDate = DateTime.Now.ToString()
            };
        }
        public async Task <IActionResult> Update(EmployeeUpdate model)
        {
            if (model.MobileNumber.StartsWith('0'))
            {
                model.MobileNumber = "962" + model.MobileNumber.Substring(1);
            }
            else
            {
                model.MobileNumber = "962" + model.MobileNumber;
            }

            Employee emp = await _db.Employees.Where(x => x.Id == model.Id).FirstOrDefaultAsync();

            long userId = _principalService.GetUserId();

            emp.FullNameAr        = model.FullNameAr;
            emp.FullNameEn        = model.FullNameEn;
            emp.Address           = model.Address;
            emp.Email             = model.Email;
            emp.Address           = model.Address;
            emp.MobileNumber      = model.MobileNumber;
            emp.Address           = model.Address;
            emp.Department        = model.Department;
            emp.JobTitleName      = model.JobTitleName;
            emp.FamilyMemberCount = (int)model.FamilyMemberCount;
            emp.MartialStatus     = (MartialStatusEnum)model.MartialStatus;
            emp.Salary            = (int)model.Salary;
            emp.SSN        = model.SSN;
            emp.HiringDate = (DateTime)model.HiringDate;
            emp.UpdatedAt  = DateTime.Now;
            emp.UpdatedBy  = userId;

            //_db.Entry(emp).State = EntityState.Modified;
            var result = await _db.SaveChangesAsync();

            await UpdateUser(emp.UserId, model.Username, model.Email, model.Password);

            if (result == 1)
            {
                //ManageEmployeeRoles(emp.UserId, model.Role);
                return(new OkObjectResult(1));
            }
            throw new Exception("حصل خطأ");
        }
Beispiel #12
0
        // Update Employee
        public bool UpdateEmployee(EmployeeUpdate model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Employees
                    .Single(e => e.EmployeeId == model.EmployeeId && e.OwnerId == _userId);

                entity.Name         = model.Name;
                entity.Address      = model.Address;
                entity.City         = model.City;
                entity.State        = model.State;
                entity.PhoneNumber  = model.PhoneNumber;
                entity.EmailAddress = model.EmailAddress;
                entity.LastUpdated  = DateTimeOffset.Now;

                return(ctx.SaveChanges() == 1);
            }
        }
        public void GetXmlTest()
        {
            string expected = @"<?xml version=""1.0"" encoding=""utf-8""?>
<function controlid=""unittest"">
    <update>
        <EMPLOYEE>
            <EMPLOYEEID>E1234</EMPLOYEEID>
        </EMPLOYEE>
    </update>
</function>";

            Stream            stream      = new MemoryStream();
            XmlWriterSettings xmlSettings = new XmlWriterSettings();

            xmlSettings.Encoding    = Encoding.UTF8;
            xmlSettings.Indent      = true;
            xmlSettings.IndentChars = "    ";

            IaXmlWriter xml = new IaXmlWriter(stream, xmlSettings);

            EmployeeUpdate record = new EmployeeUpdate("unittest");

            record.EmployeeId = "E1234";

            record.WriteXml(ref xml);

            xml.Flush();
            stream.Position = 0;
            StreamReader reader = new StreamReader(stream);

            Diff xmlDiff = DiffBuilder.Compare(expected).WithTest(reader.ReadToEnd())
                           .WithDifferenceEvaluator(DifferenceEvaluators.Default)
                           .Build();

            Assert.IsFalse(xmlDiff.HasDifferences(), xmlDiff.ToString());
        }
        public ActionResult Update(int id, EmployeeUpdate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.EmployeeId != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }

            var service = CreateEmployeeService();

            if (service.UpdateEmployee(model))
            {
                TempData["SaveResult"] = "The employee has been updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Could not update the employee.");
            return(View(model));
        }
Beispiel #15
0
 public async Task UpdateEmployeeAsync(int id, EmployeeUpdate EmployeeData)
 {
     await _contactCommand.UpdateContactAsync(id,
                                              _mapper.Map <Database.Entities.Contact>(EmployeeData));
 }
Beispiel #16
0
        public async Task <IActionResult> PutEmployee(int id, EmployeeUpdate employee)
        {
            var identity = HttpContext.User.Identity as ClaimsIdentity;

            IEnumerable <Claim> claim = identity.Claims;

            var RoleClaim = claim
                            .Where(x => x.Type == ClaimTypes.Role)
                            .FirstOrDefault();

            var usernameClaim = claim
                                .Where(x => x.Type == ClaimTypes.Name)
                                .FirstOrDefault();

            var userName = await _context.User
                           .Where(x => x.Id == Int32.Parse(usernameClaim.Value))
                           .AsNoTracking()
                           .FirstOrDefaultAsync();

            var employeeobj = await _context.Employee
                              .Where(x => x.EmployeeNumber == id)
                              .FirstOrDefaultAsync();

            EmployeeSurvey employeessurveyobj = new EmployeeSurvey();

            if (userName == null)
            {
                return(BadRequest(new { message = "Woops, that user doesn't exist" }));
            }

            bool isAdmin = RoleClaim.Value == "admin";
            bool isSelf  = userName.EmployeeNumber == id;

            if (isAdmin || isSelf)
            {
                if (employee.Age > 0)
                {
                    employeeobj.Age = employee.Age;
                }

                if (employee.Attrition != null)
                {
                    employeeobj.Attrition = employee.Attrition ?? default(bool);
                }

                if (employee.BusinessTravel != null)
                {
                    var BusinessTravel = await _context.BusinessTravel
                                         .AsNoTracking()
                                         .FirstOrDefaultAsync(x => x.BusinessTravel1 == employee.BusinessTravel);

                    if (BusinessTravel != null)
                    {
                        employeeobj.BusinessTravel = BusinessTravel.BusinessTravelId;
                    }
                    else
                    {
                        return(BadRequest(new { message = "Business Travel Value needs to match the table's value or you need to add a new value" }));
                    }
                }

                if (employee.DailyRate > 0)
                {
                    employeeobj.DailyRate = employee.DailyRate;
                }

                if (employee.Department != null)
                {
                    var Department = await _context.Department
                                     .AsNoTracking()
                                     .FirstOrDefaultAsync(x => x.Department1 == employee.Department);

                    if (Department != null)
                    {
                        employeeobj.Department = Department.DepartmentId;
                    }
                    else
                    {
                        return(BadRequest(new { message = "Department Value needs to match the table's value or you need to add a new department" }));
                    }
                }

                if (employee.DistanceFromHome > 0)
                {
                    employeeobj.DistanceFromHome = employee.DistanceFromHome;
                }

                if (employee.Education > 0)
                {
                    employeeobj.Education = employee.Education;
                }

                if (employee.Education > 0)
                {
                    employeeobj.Education = employee.Education;
                }

                if (employee.EducationField != null)
                {
                    var EducationField = await _context.EducationField
                                         .AsNoTracking()
                                         .FirstOrDefaultAsync(x => x.EducationField1 == employee.EducationField);

                    if (EducationField != null)
                    {
                        employeeobj.EducationField = EducationField.EducationFieldId;
                    }
                    else
                    {
                        return(BadRequest(new { message = "Education Field Value needs to match the table's value or you need to add a new Education Field" }));
                    }
                }

                if (employee.Gender != null)
                {
                    var Gender = await _context.Gender
                                 .AsNoTracking()
                                 .FirstOrDefaultAsync(x => x.Gender1 == employee.Gender);

                    if (Gender != null)
                    {
                        employeeobj.EducationField = Gender.GenderId;
                    }
                    else
                    {
                        return(BadRequest(new { message = "That Gender Value needs to match the table's value or you need to add a new Gender" }));
                    }
                }

                if (employee.HourlyRate > 0 && !isAdmin)
                {
                    return(Forbid());
                }
                else if (employee.HourlyRate > 0 && isAdmin)
                {
                    employeeobj.HourlyRate = employee.HourlyRate;
                }

                if (employee.JobInvolvement > 0)
                {
                    employeeobj.JobInvolvement = employee.JobInvolvement;
                }

                if (employee.JobLevel > 0)
                {
                    employeeobj.JobLevel = employee.JobLevel;
                }

                if (employee.MaritalStatus != null)
                {
                    var MaritalStatus = await _context.MaritalStatus
                                        .AsNoTracking()
                                        .FirstOrDefaultAsync(x => x.MaritalStatus1 == employee.MaritalStatus);

                    if (MaritalStatus != null)
                    {
                        employeeobj.MaritalStatus = MaritalStatus.MaritalStatusId;
                    }
                    else
                    {
                        return(BadRequest(new { message = "That Marital Status needs to match the table's value or you need to add a new Marital Status" }));
                    }
                }

                if (employee.MonthlyIncome > 0 && !isAdmin)
                {
                    return(Forbid());
                }
                else if (employee.MonthlyIncome > 0 && isAdmin)
                {
                    employeeobj.MonthlyIncome = employee.MonthlyIncome;
                }

                if (employee.MonthlyRate > 0 && !isAdmin)
                {
                    return(Forbid());
                }
                else if (employee.MonthlyRate > 0 && isAdmin)
                {
                    employeeobj.MonthlyRate = employee.MonthlyRate;
                }

                if (employee.NumCompaniesWorked > 0)
                {
                    employeeobj.NumCompaniesWorked = employee.NumCompaniesWorked;
                }

                if (employee.OverTime != null)
                {
                    employeeobj.OverTime = employee.OverTime ?? default(bool);
                }

                if (employee.PercentSalaryHike > 0 && !isAdmin)
                {
                    return(Forbid());
                }
                else if (employee.PercentSalaryHike > 0 && isAdmin)
                {
                    employeeobj.PercentSalaryHike = employee.PercentSalaryHike;
                }


                if (employee.PerformanceRating > 0 && !isAdmin)
                {
                    return(Forbid());
                }
                else if (employee.PerformanceRating > 0 && isAdmin)
                {
                    employeeobj.PerformanceRating = employee.PerformanceRating;
                }

                if (employee.StandardHours > 0)
                {
                    employeeobj.StandardHours = employee.StandardHours;
                }

                if (employee.StockOptionLevel > 0)
                {
                    employeeobj.StockOptionLevel = employee.StockOptionLevel;
                }

                if (employee.TotalWorkingYears > 0)
                {
                    employeeobj.TotalWorkingYears = employee.TotalWorkingYears;
                }

                if (employee.TrainingTimesLastYear > 0)
                {
                    employeeobj.TrainingTimesLastYear = employee.TrainingTimesLastYear;
                }

                if (employee.YearsAtCompany > 0)
                {
                    employeeobj.YearsAtCompany = employee.YearsAtCompany;
                }

                if (employee.YearsInCurrentRole > 0)
                {
                    employeeobj.YearsInCurrentRole = employee.YearsInCurrentRole;
                }

                if (employee.YearsSinceLastPromotion > 0)
                {
                    employeeobj.YearsSinceLastPromotion = employee.YearsSinceLastPromotion;
                }

                if (employee.YearsWithCurrManager > 0)
                {
                    employeeobj.YearsWithCurrManager = employee.YearsWithCurrManager;
                }

                int surveycount = 0;

                if (employee.EnvironmentSatisfaction > 0)
                {
                    employeessurveyobj.EnvironmentSatisfaction = employee.EnvironmentSatisfaction;
                    surveycount++;
                }
                if (employee.RelationshipSatisfaction > 0)
                {
                    employeessurveyobj.RelationshipSatisfaction = employee.RelationshipSatisfaction;
                    surveycount++;
                }
                if (employee.JobSatisfaction > 0)
                {
                    employeessurveyobj.JobSatisfaction = employee.JobSatisfaction;
                    surveycount++;
                }
                if (employee.WorkLifeBalance > 0)
                {
                    employeessurveyobj.WorkLifeBalance = employee.WorkLifeBalance;
                    surveycount++;
                }
                if (surveycount == 4) //if all values added then add new survey
                {
                    employeessurveyobj.EmployeeId = id;
                    _context.EmployeeSurvey.Add(employeessurveyobj);
                }
                else if (surveycount > 0 && surveycount != 4) //if some values added, I assume you're fixing a survey mistake.
                {
                    var employeessurveyobjoriginal = await _context.EmployeeSurvey
                                                     .OrderByDescending(x => x.EmployeeId == id)
                                                     .FirstOrDefaultAsync();

                    employeessurveyobjoriginal.EnvironmentSatisfaction = employeessurveyobj.EnvironmentSatisfaction > 0 ? default(byte) : employeessurveyobj.EnvironmentSatisfaction;
                    employeessurveyobjoriginal.EnvironmentSatisfaction = employeessurveyobj.RelationshipSatisfaction > 0 ? default(byte) : employeessurveyobj.RelationshipSatisfaction;
                    employeessurveyobjoriginal.EnvironmentSatisfaction = employeessurveyobj.JobSatisfaction > 0 ? default(byte) : employeessurveyobj.JobSatisfaction;
                    employeessurveyobjoriginal.EnvironmentSatisfaction = employeessurveyobj.WorkLifeBalance > 0 ? default(byte) : employeessurveyobj.WorkLifeBalance;

                    _context.Entry(employeessurveyobjoriginal).State = EntityState.Modified;
                }



                var latestemployeesurvey = await _context.EmployeeSurvey
                                           .AsNoTracking()
                                           .OrderByDescending(x => x.EmployeeId == id)
                                           .FirstOrDefaultAsync();

                employeeobj.EmployeeSurvey = latestemployeesurvey.SurveyId;

                _context.Entry(employeeobj).State = EntityState.Modified;

                try
                {
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EmployeeExists(id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            else
            {
                return(Forbid());
            }

            return(Ok(new { message = "Modified Employee: " + id + " with provided values.\n" + employee }));
        }
Beispiel #17
0
 public IHttpActionResult Update(int id, EmployeeUpdate employee)
 {
     employee.Id = id;
     _employeeService.Update(employee);
     return(Ok());
 }
        /// <summary>
        /// Synchronizes a set of employees using a connected IntacctClient
        /// </summary>
        /// <param name="client">The Client to sync to</param>
        /// <param name="orgemployees">Customer Data to Send</param>
        private async Task SyncOrgEmployees(OnlineClient client, IEnumerable <IntacctEmployee> orgemployees, PerformContext context)
        {
            IDictionary <string, string> employeemap = await GetEmployeeIds(client, context);

            IList <string> contactNames = await GetContacts(client, context);

            // Filter Existing Out
            if (SyncOnlyNew)
            {
                context.WriteLine("Filtering out Existing Employees");
                orgemployees = orgemployees.Where(c => !contactNames.Contains(IntacctCleanString(c.EMPLOYEENAME))).ToArray();
            }

            // Send in batches of Employees
            int sent  = 0;
            int total = orgemployees.Count();

            while (sent < total)
            {
                // What's in this batch
                var batchData = orgemployees.Skip(sent).Take(50).ToList();
                context.WriteLine("Preparing Batch of 50 ({0} - {1} of {2})", sent, sent + batchData.Count, total);
                sent += batchData.Count;

                // Create the Batch for Intacct
                List <IFunction> batchFunctions = new List <IFunction>();
                foreach (var employee in batchData)
                {
                    // Process the Contact First
                    if (contactNames.Contains(IntacctCleanString(employee.EMPLOYEENAME)))
                    {
                        // Update the Contact
                        ContactUpdate update = new ContactUpdate
                        {
                            PrintAs             = employee.EMPLOYEENAME,
                            ContactName         = IntacctCleanString(employee.EMPLOYEENAME),
                            FirstName           = employee.FIRSTNAME,
                            LastName            = employee.LASTNAME,
                            Active              = employee.EMPLOYEEACTIVE == "active",
                            PrimaryPhoneNo      = employee.PHONE,
                            PrimaryEmailAddress = employee.EMAIL
                        };
                        batchFunctions.Add(update);
                    }
                    else
                    {
                        // Create the Contact
                        ContactCreate create = new ContactCreate
                        {
                            PrintAs             = employee.EMPLOYEENAME,
                            ContactName         = IntacctCleanString(employee.EMPLOYEENAME),
                            FirstName           = employee.FIRSTNAME,
                            LastName            = employee.LASTNAME,
                            Active              = employee.EMPLOYEEACTIVE == "active",
                            PrimaryPhoneNo      = employee.PHONE,
                            PrimaryEmailAddress = employee.EMAIL
                        };
                        batchFunctions.Add(create);
                        // Add to our List, so we don't update duplicates
                        contactNames.Add(employee.EMPLOYEENAME);
                    }

                    // Process the Employee Now
                    if (employeemap.ContainsKey(employee.EMPLOYEEID))
                    {
                        // Update the Employee
                        EmployeeUpdate update = new EmployeeUpdate
                        {
                            EmployeeId   = employee.EMPLOYEEID,
                            ContactName  = IntacctCleanString(employee.EMPLOYEENAME),
                            DepartmentId = employee.DEPARTMENTID,
                            LocationId   = employee.LOCATIONID,
                            Active       = employee.EMPLOYEEACTIVE == "active",
                            StartDate    = employee.EMPLOYEESTART,
                            EndDate      = employee.EMPLOYEETERMINATION.ToIntacctDate()
                        };
                        if (!String.IsNullOrWhiteSpace(employee.PE_STAFF_CODE))
                        {
                            update.CustomFields.Add("PE_STAFF_CODE", employee.PE_STAFF_CODE);
                        }
                        update.CustomFields.Add("RECORDNO", employeemap[employee.EMPLOYEEID]);
                        batchFunctions.Add(update);
                    }
                    else
                    {
                        // Create the Employee
                        EmployeeCreate create = new EmployeeCreate
                        {
                            EmployeeId   = employee.EMPLOYEEID,
                            ContactName  = IntacctCleanString(employee.EMPLOYEENAME),
                            DepartmentId = employee.DEPARTMENTID,
                            LocationId   = employee.LOCATIONID,
                            Active       = employee.EMPLOYEEACTIVE == "active",
                            StartDate    = employee.EMPLOYEESTART,
                            EndDate      = employee.EMPLOYEETERMINATION.ToIntacctDate()
                        };
                        if (!String.IsNullOrWhiteSpace(employee.PE_STAFF_CODE))
                        {
                            create.CustomFields.Add("PE_STAFF_CODE", employee.PE_STAFF_CODE);
                        }
                        batchFunctions.Add(create);
                    }
                }

                // Send the Batch to Intacct
                context.WriteLine("Sending Batch to Intacct");
                var response = await client.ExecuteBatch(batchFunctions);

                context.WriteLine("Inspecting Response from Intacct");
                foreach (var result in response.Results)
                {
                    if (result.Errors != null)
                    {
                        context.SetTextColor(ConsoleTextColor.Red);
                        context.WriteLine("==================================");
                        foreach (var err in result.Errors)
                        {
                            context.WriteLine(err);
                        }
                        context.WriteLine("==================================");
                        context.WriteLine();
                        Console.ResetColor();
                    }
                }
            }
        }
 public async Task Update([FromBody] EmployeeUpdate employee) => await business.Update(employee);