public async Task<CallEmotion> Get(long Id) { CallEmotion CallEmotion = await DataContext.CallEmotion.AsNoTracking() .Where(x => x.Id == Id) .Where(x => x.DeletedAt == null) .Select(x => new CallEmotion() { CreatedAt = x.CreatedAt, UpdatedAt = x.UpdatedAt, Id = x.Id, Code = x.Code, Name = x.Name, StatusId = x.StatusId, Description = x.Description, Used = x.Used, RowId = x.RowId, Status = x.Status == null ? null : new Status { Id = x.Status.Id, Code = x.Status.Code, Name = x.Status.Name, }, }).FirstOrDefaultAsync(); if (CallEmotion == null) return null; return CallEmotion; }
public async Task <bool> Delete(CallEmotion CallEmotion) { if (await ValidateId(CallEmotion)) { } return(CallEmotion.IsValidated); }
public async Task <CallEmotion> Get(long Id) { CallEmotion CallEmotion = await UOW.CallEmotionRepository.Get(Id); if (CallEmotion == null) { return(null); } return(CallEmotion); }
public CallLog_CallEmotionDTO(CallEmotion CallEmotion) { this.Id = CallEmotion.Id; this.Name = CallEmotion.Name; this.Code = CallEmotion.Code; this.StatusId = CallEmotion.StatusId; this.Description = CallEmotion.Description; this.Errors = CallEmotion.Errors; }
public async Task<bool> Update(CallEmotion CallEmotion) { CallEmotionDAO CallEmotionDAO = DataContext.CallEmotion.Where(x => x.Id == CallEmotion.Id).FirstOrDefault(); if (CallEmotionDAO == null) return false; CallEmotionDAO.Id = CallEmotion.Id; CallEmotionDAO.Code = CallEmotion.Code; CallEmotionDAO.Name = CallEmotion.Name; CallEmotionDAO.StatusId = CallEmotion.StatusId; CallEmotionDAO.Description = CallEmotion.Description; CallEmotionDAO.Used = CallEmotion.Used; CallEmotionDAO.RowId = CallEmotion.RowId; CallEmotionDAO.UpdatedAt = StaticParams.DateTimeNow; await DataContext.SaveChangesAsync(); await SaveReference(CallEmotion); return true; }
public Company_CallEmotionDTO(CallEmotion CallEmotion) { this.Id = CallEmotion.Id; this.Code = CallEmotion.Code; this.Name = CallEmotion.Name; this.StatusId = CallEmotion.StatusId; this.Description = CallEmotion.Description; this.Used = CallEmotion.Used; this.RowId = CallEmotion.RowId; this.Errors = CallEmotion.Errors; }
public async Task<bool> Create(CallEmotion CallEmotion) { CallEmotionDAO CallEmotionDAO = new CallEmotionDAO(); CallEmotionDAO.Id = CallEmotion.Id; CallEmotionDAO.Code = CallEmotion.Code; CallEmotionDAO.Name = CallEmotion.Name; CallEmotionDAO.StatusId = CallEmotion.StatusId; CallEmotionDAO.Description = CallEmotion.Description; CallEmotionDAO.Used = CallEmotion.Used; CallEmotionDAO.RowId = CallEmotion.RowId; CallEmotionDAO.CreatedAt = StaticParams.DateTimeNow; CallEmotionDAO.UpdatedAt = StaticParams.DateTimeNow; DataContext.CallEmotion.Add(CallEmotionDAO); await DataContext.SaveChangesAsync(); CallEmotion.Id = CallEmotionDAO.Id; await SaveReference(CallEmotion); return true; }
public async Task <bool> ValidateId(CallEmotion CallEmotion) { CallEmotionFilter CallEmotionFilter = new CallEmotionFilter { Skip = 0, Take = 10, Id = new IdFilter { Equal = CallEmotion.Id }, Selects = CallEmotionSelect.Id }; int count = await UOW.CallEmotionRepository.Count(CallEmotionFilter); if (count == 0) { CallEmotion.AddError(nameof(CallEmotionValidator), nameof(CallEmotion.Id), ErrorCode.IdNotExisted); } return(count == 1); }
public async Task <CallEmotion> Delete(CallEmotion CallEmotion) { if (!await CallEmotionValidator.Delete(CallEmotion)) { return(CallEmotion); } try { await UOW.CallEmotionRepository.Delete(CallEmotion); await Logging.CreateAuditLog(new { }, CallEmotion, nameof(CallEmotionService)); return(CallEmotion); } catch (Exception ex) { await Logging.CreateSystemLog(ex, nameof(CallEmotionService)); } return(null); }
public async Task <CallEmotion> Update(CallEmotion CallEmotion) { if (!await CallEmotionValidator.Update(CallEmotion)) { return(CallEmotion); } try { var oldData = await UOW.CallEmotionRepository.Get(CallEmotion.Id); await UOW.CallEmotionRepository.Update(CallEmotion); CallEmotion = await UOW.CallEmotionRepository.Get(CallEmotion.Id); await Logging.CreateAuditLog(CallEmotion, oldData, nameof(CallEmotionService)); return(CallEmotion); } catch (Exception ex) { await Logging.CreateSystemLog(ex, nameof(CallEmotionService)); } return(null); }
private async Task SaveReference(CallEmotion CallEmotion) { }
public async Task<bool> Delete(CallEmotion CallEmotion) { await DataContext.CallEmotion.Where(x => x.Id == CallEmotion.Id).UpdateFromQueryAsync(x => new CallEmotionDAO { DeletedAt = StaticParams.DateTimeNow, UpdatedAt = StaticParams.DateTimeNow }); return true; }
public async Task <bool> Create(CallEmotion CallEmotion) { return(CallEmotion.IsValidated); }
public async Task <ActionResult> Import(IFormFile file) { if (UnAuthorization) { return(Forbid()); } if (!ModelState.IsValid) { throw new BindException(ModelState); } AppUserFilter AppUserFilter = new AppUserFilter { Skip = 0, Take = int.MaxValue, Selects = AppUserSelect.ALL }; List <AppUser> AppUsers = await AppUserService.List(AppUserFilter); EntityReferenceFilter EntityReferenceFilter = new EntityReferenceFilter { Skip = 0, Take = int.MaxValue, Selects = EntityReferenceSelect.ALL }; List <EntityReference> EntityReferences = await EntityReferenceService.List(EntityReferenceFilter); CallTypeFilter CallTypeFilter = new CallTypeFilter { Skip = 0, Take = int.MaxValue, Selects = CallTypeSelect.ALL }; List <CallType> CallTypes = await CallTypeService.List(CallTypeFilter); CallEmotionFilter CallEmotionFilter = new CallEmotionFilter { Skip = 0, Take = int.MaxValue, Selects = CallEmotionSelect.ALL }; List <CallEmotion> CallEmotions = await CallEmotionService.List(CallEmotionFilter); List <CallLog> CallLogs = new List <CallLog>(); using (ExcelPackage excelPackage = new ExcelPackage(file.OpenReadStream())) { ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets.FirstOrDefault(); if (worksheet == null) { return(Ok(CallLogs)); } int StartColumn = 1; int StartRow = 1; int IdColumn = 0 + StartColumn; int EntityReferenceIdColumn = 1 + StartColumn; int CallTypeIdColumn = 2 + StartColumn; int CallEmotionIdColumn = 3 + StartColumn; int AppUserIdColumn = 4 + StartColumn; int TitleColumn = 5 + StartColumn; int ContentColumn = 6 + StartColumn; int PhoneColumn = 7 + StartColumn; int CallTimeColumn = 8 + StartColumn; int UsedColumn = 12 + StartColumn; for (int i = StartRow; i <= worksheet.Dimension.End.Row; i++) { if (string.IsNullOrEmpty(worksheet.Cells[i + StartRow, StartColumn].Value?.ToString())) { break; } string IdValue = worksheet.Cells[i + StartRow, IdColumn].Value?.ToString(); string EntityReferenceIdValue = worksheet.Cells[i + StartRow, EntityReferenceIdColumn].Value?.ToString(); string CallTypeIdValue = worksheet.Cells[i + StartRow, CallTypeIdColumn].Value?.ToString(); string CallEmotionIdValue = worksheet.Cells[i + StartRow, CallEmotionIdColumn].Value?.ToString(); string AppUserIdValue = worksheet.Cells[i + StartRow, AppUserIdColumn].Value?.ToString(); string TitleValue = worksheet.Cells[i + StartRow, TitleColumn].Value?.ToString(); string ContentValue = worksheet.Cells[i + StartRow, ContentColumn].Value?.ToString(); string PhoneValue = worksheet.Cells[i + StartRow, PhoneColumn].Value?.ToString(); string CallTimeValue = worksheet.Cells[i + StartRow, CallTimeColumn].Value?.ToString(); string UsedValue = worksheet.Cells[i + StartRow, UsedColumn].Value?.ToString(); CallLog CallLog = new CallLog(); CallLog.Title = TitleValue; CallLog.Content = ContentValue; CallLog.Phone = PhoneValue; CallLog.CallTime = DateTime.TryParse(CallTimeValue, out DateTime CallTime) ? CallTime : DateTime.Now; AppUser AppUser = AppUsers.Where(x => x.Id.ToString() == AppUserIdValue).FirstOrDefault(); CallLog.AppUserId = AppUser == null ? 0 : AppUser.Id; CallLog.AppUser = AppUser; EntityReference EntityReference = EntityReferences.Where(x => x.Id.ToString() == EntityReferenceIdValue).FirstOrDefault(); CallLog.EntityReferenceId = EntityReference == null ? 0 : EntityReference.Id; CallLog.EntityReference = EntityReference; CallType CallType = CallTypes.Where(x => x.Id.ToString() == CallTypeIdValue).FirstOrDefault(); CallLog.CallTypeId = CallType == null ? 0 : CallType.Id; CallLog.CallType = CallType; CallEmotion CallEmotion = CallEmotions.Where(x => x.Id.ToString() == CallEmotionIdValue).FirstOrDefault(); CallLog.CallEmotionId = CallEmotion == null ? 0 : CallEmotion.Id; CallLog.CallEmotion = CallEmotion; CallLogs.Add(CallLog); } } CallLogs = await CallLogService.Import(CallLogs); if (CallLogs.All(x => x.IsValidated)) { return(Ok(true)); } else { List <string> Errors = new List <string>(); for (int i = 0; i < CallLogs.Count; i++) { CallLog CallLog = CallLogs[i]; if (!CallLog.IsValidated) { string Error = $"Dòng {i + 2} có lỗi:"; if (CallLog.Errors.ContainsKey(nameof(CallLog.Id))) { Error += CallLog.Errors[nameof(CallLog.Id)]; } if (CallLog.Errors.ContainsKey(nameof(CallLog.EntityReferenceId))) { Error += CallLog.Errors[nameof(CallLog.EntityReferenceId)]; } if (CallLog.Errors.ContainsKey(nameof(CallLog.CallTypeId))) { Error += CallLog.Errors[nameof(CallLog.CallTypeId)]; } if (CallLog.Errors.ContainsKey(nameof(CallLog.CallEmotionId))) { Error += CallLog.Errors[nameof(CallLog.CallEmotionId)]; } if (CallLog.Errors.ContainsKey(nameof(CallLog.AppUserId))) { Error += CallLog.Errors[nameof(CallLog.AppUserId)]; } if (CallLog.Errors.ContainsKey(nameof(CallLog.Title))) { Error += CallLog.Errors[nameof(CallLog.Title)]; } if (CallLog.Errors.ContainsKey(nameof(CallLog.Content))) { Error += CallLog.Errors[nameof(CallLog.Content)]; } if (CallLog.Errors.ContainsKey(nameof(CallLog.Phone))) { Error += CallLog.Errors[nameof(CallLog.Phone)]; } if (CallLog.Errors.ContainsKey(nameof(CallLog.CallTime))) { Error += CallLog.Errors[nameof(CallLog.CallTime)]; } Errors.Add(Error); } } return(BadRequest(Errors)); } }