Esempio n. 1
0
        ///  <inheritdoc />
        public async Task <bool> DeleteDataAsync(int groupID, int jobtitleID)
        {
            using (var context = await this._contextfactory.GetContextAsync(groupID))
            {
                //Do the search
                var searchResult = await GetDataAsync(groupID, jobtitleID);

                foreach (DefaultHolidayAllowance dhol in searchResult)
                {
                    var delRecord = new DefaultHolidayAllowanceTable
                    {
                        JobTitleID   = jobtitleID,
                        YearsWorked  = dhol.YearsWorked,
                        Allowance    = dhol.Allowance,
                        DateCreated  = DateTime.UtcNow,
                        LastModified = DateTime.UtcNow
                    };

                    context.DefaultHolidayAllowances.Attach(delRecord);

                    context.DefaultHolidayAllowances.Remove(delRecord);
                }

                // Save the changes (deletions) asynchronously
                var result = await context.SaveChangesAsync();

                // Return an indication of whether any records have been updated
                return(result > 0);
            }
        }
Esempio n. 2
0
        ///  <inheritdoc />
        public async Task <bool> SetDataAsync(int groupID, List <DefaultHolidayAllowance> input)
        {
            int JobtitleID = 0;

            if (input == null)
            {
                throw new ArgumentException("Parameter \"input\" is required.");
            }

            using (var context = await this._contextfactory.GetContextAsync(groupID))
            {
                foreach (var record in input)
                {
                    //Get job title Id if not supplied
                    if (record.JobTitleID == 0)
                    {
                        JobtitleID = await GetDefaultHolidayAllowanceJobTitleIDAsync(groupID, record.JobTitleName);
                    }
                    else
                    {
                        JobtitleID = record.JobTitleID;
                    }

                    //Do the search
                    var searchResult = await GetDataAsync(groupID, JobtitleID, record.YearsWorked);

                    //add if not found..
                    if (!searchResult.Any())
                    {
                        var newRecord = new DefaultHolidayAllowanceTable
                        {
                            JobTitleID   = JobtitleID,
                            YearsWorked  = record.YearsWorked,
                            Allowance    = record.Allowance,
                            DateCreated  = DateTime.UtcNow,
                            LastModified = DateTime.UtcNow
                        };
                        context.DefaultHolidayAllowances.Add(newRecord);
                    }
                    //update if found
                    else
                    {
                        var updatedRecord = new DefaultHolidayAllowanceTable
                        {
                            JobTitleID   = searchResult.FirstOrDefault().JobTitleID,
                            YearsWorked  = searchResult.FirstOrDefault().YearsWorked,
                            Allowance    = searchResult.FirstOrDefault().Allowance,
                            LastModified = searchResult.FirstOrDefault().LastModified,
                            DateCreated  = searchResult.FirstOrDefault().DateCreated
                        };

                        context.DefaultHolidayAllowances.Attach(updatedRecord);

                        updatedRecord.Allowance    = record.Allowance;
                        updatedRecord.LastModified = DateTime.UtcNow;
                    }
                }

                // Save the changes asynchronously
                var result = await context.SaveChangesAsync();

                // Return an indication of whether any records have been updated
                //return (result > 0);
                return(true);
            }
        }