public async Task <VerifyRecordResult> UpdateAsync(WorkingLogDetailAdapterModel paraObject)
        {
            WorkingLogDetail itemData = Mapper.Map <WorkingLogDetail>(paraObject);

            CleanTrackingHelper.Clean <WorkingLogDetail>(context);
            WorkingLogDetail item = await context.WorkingLogDetail
                                    .AsNoTracking()
                                    .FirstOrDefaultAsync(x => x.Id == paraObject.Id);

            if (item == null)
            {
                return(VerifyRecordResultFactory.Build(false, ErrorMessageEnum.無法修改紀錄));
            }
            else
            {
                CleanTrackingHelper.Clean <WorkingLogDetail>(context);
                context.Entry(itemData).State = EntityState.Modified;
                await context.SaveChangesAsync();

                var id = itemData.WorkingLogId;
                CleanTrackingHelper.Clean <WorkingLogDetail>(context);
                await CountingWorkingHour(id);

                return(VerifyRecordResultFactory.Build(true));
            }
        }
        public async Task <WorkingLogDetailAdapterModel> GetAsync(int id)
        {
            WorkingLogDetail item = await context.WorkingLogDetail
                                    .AsNoTracking()
                                    .Include(x => x.Project)
                                    .FirstOrDefaultAsync(x => x.Id == id);

            WorkingLogDetailAdapterModel result = Mapper.Map <WorkingLogDetailAdapterModel>(item);

            await OhterDependencyData(result); return(result);
        }
Exemple #3
0
        public async Task <VerifyRecordResult> BeforeDeleteCheckAsync(ProjectAdapterModel paraObject)
        {
            CleanTrackingHelper.Clean <WorkingLogDetail>(context);
            WorkingLogDetail item = await context.WorkingLogDetail
                                    .AsNoTracking()
                                    .FirstOrDefaultAsync(x => x.ProjectId == paraObject.Id);

            if (item != null)
            {
                return(VerifyRecordResultFactory.Build(false, ErrorMessageEnum.該紀錄無法刪除因為有其他資料表在使用中));
            }
            return(VerifyRecordResultFactory.Build(true));
        }
        public async Task <VerifyRecordResult> AddAsync(WorkingLogDetailAdapterModel paraObject)
        {
            WorkingLogDetail itemParameter = Mapper.Map <WorkingLogDetail>(paraObject);

            CleanTrackingHelper.Clean <WorkingLogDetail>(context);
            await context.WorkingLogDetail
            .AddAsync(itemParameter);

            await context.SaveChangesAsync();

            var id = itemParameter.WorkingLogId;

            CleanTrackingHelper.Clean <WorkingLogDetail>(context);
            await CountingWorkingHour(id);

            return(VerifyRecordResultFactory.Build(true));
        }
        public async Task <VerifyRecordResult> DeleteAsync(int id)
        {
            CleanTrackingHelper.Clean <WorkingLogDetail>(context);
            WorkingLogDetail item = await context.WorkingLogDetail
                                    .AsNoTracking()
                                    .FirstOrDefaultAsync(x => x.Id == id);

            if (item == null)
            {
                return(VerifyRecordResultFactory.Build(false, ErrorMessageEnum.無法刪除紀錄));
            }
            else
            {
                CleanTrackingHelper.Clean <WorkingLogDetail>(context);
                context.Entry(item).State = EntityState.Deleted;
                await context.SaveChangesAsync();

                var pid = item.WorkingLogId;
                CleanTrackingHelper.Clean <WorkingLogDetail>(context);
                await CountingWorkingHour(pid);

                return(VerifyRecordResultFactory.Build(true));
            }
        }