Ejemplo n.º 1
0
        public async Task <QueueResult> Handle(string data)
        {
            QueueResult result = new QueueResult(Data.Enums.ProcessType.EditOffice);

            if (string.IsNullOrEmpty(data))
            {
                result.ExceptionCode = ExceptionCode.MissingQueueData;
            }
            OfficeQueue officeQueue = null;

            try
            {
                officeQueue = JsonConvert.DeserializeObject <OfficeQueue>(data);
                OfficeLogic officeLogic = new OfficeLogic(this.db, result.AdditionalData, this.loggerFactory);
                await officeLogic.EditOffice(officeQueue);

                result.AdditionalData.Add("officeId", officeQueue.Id.ToString());
                result.AdditionalData.Add("officeName", officeQueue.Name);

                result.Status = Status.Success;
            }
            catch (Exception ex)
            {
                HandleException(ex, result, officeQueue);
            }
            return(result);
        }
Ejemplo n.º 2
0
        private async Task CheckDelete(OfficeQueue officeQueue)
        {
            var relatedTerms = await this.db.GetAllTermsForOffice(officeQueue.TenantId, officeQueue.Id.Value).FirstOrDefaultAsync();

            if (relatedTerms != null)
            {
                throw new OfficeHasRelatedTerm($"Office ({officeQueue.Id}) has related term ({relatedTerms.Id})", relatedTerms.Id, relatedTerms.Start, relatedTerms.End);
            }
        }
Ejemplo n.º 3
0
        public async Task DeleteOffice(OfficeQueue officeQueue)
        {
            await CheckDelete(officeQueue);

            Office office = await this.db.GetOfficeById(officeQueue.TenantId, officeQueue.Id.Value).FirstOrDefaultAsync();

            this.db.Offices.Remove(office);
            await this.db.SaveChangesAsync();

            this.logger.LogCustomInformation($"Office '{office.Name}' with id '{office.Id}' has successfully deleted", officeQueue.TenantId.ToString(), officeQueue.UserPerformingAction.ToString());
        }
Ejemplo n.º 4
0
        public async Task EditOffice(OfficeQueue officeQueue)
        {
            await CheckAddEdit(officeQueue);

            Office office = await this.db.GetOfficeById(officeQueue.TenantId, officeQueue.Id.Value).FirstOrDefaultAsync();

            office.Name    = officeQueue.Name;
            office.Address = officeQueue.Address;
            office.CityId  = officeQueue.CityId;
            office.Status  = officeQueue.Status;

            await this.db.SaveChangesAsync();

            this.logger.LogCustomInformation($"Office '{office.Name}' with id '{office.Id}' has successfully updated", officeQueue.TenantId.ToString(), officeQueue.UserPerformingAction.ToString());
        }
Ejemplo n.º 5
0
        public async Task EditOffice(OfficeVM office)
        {
            OfficeQueue officeQueue = Mapper.Map <OfficeVM, OfficeQueue>(office, options => {
                options.AfterMap((src, dest) => dest.UserPerformingAction = this.UserId);
                options.AfterMap((src, dest) => dest.TenantId             = this.TenantId);
            });

            ProcessQueueHistory processQueueHistory = new ProcessQueueHistory()
            {
                Data      = JsonConvert.SerializeObject(officeQueue),
                AddedById = this.UserId,
                TenantId  = this.TenantId,
                Status    = Data.Enums.ResultStatus.Waiting,
                Type      = Data.Enums.ProcessType.EditOffice
            };

            await this.queueHandler.AddToQueue(processQueueHistory);
        }
Ejemplo n.º 6
0
        public async Task <Guid> AddOffice(OfficeQueue officeQueue)
        {
            await CheckAddEdit(officeQueue);

            Office office = new Office()
            {
                Name     = officeQueue.Name,
                Address  = officeQueue.Address,
                CityId   = officeQueue.CityId,
                Status   = officeQueue.Status,
                TenantId = officeQueue.TenantId
            };

            this.db.Offices.Add(office);
            await this.db.SaveChangesAsync();

            this.logger.LogCustomInformation($"Office '{office.Name}' with id '{office.Id}' has successfully created", officeQueue.TenantId.ToString(), officeQueue.UserPerformingAction.ToString());
            return(office.Id);
        }
Ejemplo n.º 7
0
        public async Task DeleteOffice(Guid id)
        {
            OfficeQueue officeQueue = new OfficeQueue()
            {
                Id                   = id,
                TenantId             = this.TenantId,
                UserPerformingAction = this.UserId
            };

            ProcessQueueHistory processQueueHistory = new ProcessQueueHistory()
            {
                Data      = JsonConvert.SerializeObject(officeQueue),
                AddedById = this.UserId,
                TenantId  = this.TenantId,
                Status    = Data.Enums.ResultStatus.Waiting,
                Type      = Data.Enums.ProcessType.DeleteOffice
            };

            await this.queueHandler.AddToQueue(processQueueHistory);
        }
Ejemplo n.º 8
0
 private async Task CheckAddEdit(OfficeQueue officeQueue)
 {
     await CheckForSameName(officeQueue.Name.Trim(), officeQueue.Id, officeQueue.TenantId);
 }