コード例 #1
0
        public async Task CreateAndSendEmailAsync(TenantRequest tenantRequest)
        {
            //var connectionString =
            //    "DefaultEndpointsProtocol=https;AccountName=demorrstorageaccount;AccountKey=NXluNSsP4tm+NViZ65rN6eM4V6Eniko9b7NON3M5xZGaDmGMV0LSIsM9CUVdFe+2n5L8vyl4DtdaVZz+JMJ3iA==;EndpointSuffix=core.windows.net";

            var model = new NotificationQueueModel()
            {
                TenantRequestModel = _modelMapper.CopyFrom(tenantRequest),
            };
            var det = base.GetWorkerDetails(tenantRequest);

            model.WorkerModel = det == null ? null : _modelMapper.CopyFrom(det);

            var message = _modelSerializer.Serialize(model);

            //var connectionString = "UseDevelopmentStorage=true";


            //// Instantiate a QueueClient which will be used to create and manipulate the queue
            //QueueClient queueClient = new QueueClient(connectionString, "service-requests-queue");// "ServiceRequestsQueue");
            //// Create the queue
            //await queueClient.CreateIfNotExistsAsync();
            //// Send a message to the queue

            //await queueClient.SendMessageAsync(message); //Base64Encode(message));
            await _queueClient.SendMessage(message);

            // Async receive the message
            //QueueMessage[] retrievedMessage = await queueClient.ReceiveMessagesAsync();

            //var tr = _modelMappers.CopyFrom(retrievedMessage[0].MessageText);
        }
コード例 #2
0
        public void AddTenantRequest(TenantRequest tTenantRequest)
        {
            TableOperation operation = TableOperation.InsertOrReplace(_entityMapper.CopyFrom(tTenantRequest));
            var            tbl       = _dbContext.RequestCloudTable;

            tbl.Execute(operation);
        }
コード例 #3
0
        public async Task Update(Guid id, TenantRequest request)
        {
            if (request == null)
            {
                _logger.LogError($"[Update] Argument {nameof(request)} is null");
                throw new ArgumentNullException(nameof(request));
            }

            var serviceProviders = await _serviceProviderRepository.GetAsync();

            if (serviceProviders.Any(x => x.TenantName.ToLower() == request.Name.ToLower() && x.Id != id))
            {
                _logger.LogError($"[Update] Duplicate parameter: {nameof(request.Name)}");
                throw new DuplicateNameException();
            }

            var serviceProvider = serviceProviders.FirstOrDefault(x => x.Id == id);

            if (serviceProvider == null)
            {
                _logger.LogError($"[Update] ServiceProvider with parameter: {nameof(id)} not found");
                throw new KeyNotFoundException(nameof(id));
            }

            serviceProvider.TenantName = request.Name;
            serviceProvider.Phone      = request.Phone;
            await _serviceProviderRepository.UpdateAsync(serviceProvider);
        }
コード例 #4
0
 public object Post(TenantRequest req)
 {
     db.Insert(new Tenant {
         CreatedDate = DateTime.Now
     }.PopulateWith(req));
     return ...
 }
コード例 #5
0
        public async Task UpdateByCompanyId(int companyId, TenantRequest request)
        {
            if (request == null)
            {
                _logger.LogError($"[Update] Argument {nameof(request)} is null");
                throw new ArgumentNullException(nameof(request));
            }

            var tenants = await _tenantRepository.GetAsync();

            if (tenants.Any(x => x.TenantName.ToLower() == request.Name.ToLower() &&
                            x.Companies.Select(c => c.Id).Contains(companyId)))
            {
                _logger.LogError($"[Update] Duplicate parameter: {nameof(request.Name)}");
                throw new DuplicateNameException();
            }

            var tenant = tenants.FirstOrDefault(x => x.Companies.Select(c => c.Id).Contains(companyId));

            if (tenant == null)
            {
                _logger.LogError($"[Update] Tenant with parameter: {nameof(companyId)} not found");
                throw new KeyNotFoundException(nameof(companyId));
            }

            tenant.TenantName = request.Name;
            tenant.Phone      = request.Phone;
            await _tenantRepository.UpdateAsync(tenant);
        }
コード例 #6
0
        public void UpdateTenantRequest(TenantRequest tTenantRequest)
        {
            var tbl = _entityMapper.CopyFrom(tTenantRequest);

            tbl.ETag = "*";
            TableOperation operation = TableOperation.Merge(tbl);

            _dbContext.RequestCloudTable.Execute(operation);

            if (tTenantRequest.RequestStatus == TenantRequestStatusEnum.Scheduled)
            {
                var change = tTenantRequest.RequestChanges.LastOrDefault(x =>
                                                                         x.TenantRequestStatus == TenantRequestStatusEnum.Scheduled);
                if (change?.Command != null)
                {
                    var command = change.Command as ScheduleServiceWorkCommand;

                    operation = TableOperation.InsertOrReplace(new WorkerRequestTbl(command.WorkerEmailAddress, tTenantRequest.Id)
                    {
                        TenantEmail = tTenantRequest.TenantEmail
                    });
                    _dbContext.WorkerRequestsCloudTable.Execute(operation);
                }
            }
        }
コード例 #7
0
 public object Post(TenantRequest req)
 {
     db.Insert(new Tenant {
         CreatedDate = DateTime.Now
     }.PopulateWith(req));
     return(new { Id = db.GetLastInsertId() });
 }
        public void WhenIDeclineTheTenantRequest()
        {
            //Creating a Class
            TenantRequest obj = new TenantRequest();

            //Creating Method
            obj.DeclineTenantRequest();
        }
コード例 #9
0
        public EmailInfo CreateTenantRequestEmail(TenantRequest tenantRequest, Worker worker)
        {
            _tenantRequest = tenantRequest;
            _worker        = worker;
            var message = CreateMessageOnStatusChange();

            return(message == null ? null : CreateEmail(message));
        }
コード例 #10
0
        public void UpdateTenantRequest(TenantRequest tTenantRequest)
        {
            var exist = _context.TenantRequestTbl.Find(tTenantRequest.Id);

            _context.Entry(exist).CurrentValues.SetValues(_entityMapper.CopyFrom(tTenantRequest));


            _context.SaveChanges();
        }
コード例 #11
0
    public object Post(TenantRequest req)
    {
        var tenant = new Tenant {
            CreatedDate = DateTime.Now
        }.PopulateWith(req);

        Db.Save(tenant);
        return(new { Id = tenant.Id });
    }
コード例 #12
0
        public void UpdateTenantRequest(TenantRequest tTenantRequest)
        {
            if (!_requests.ContainsKey(tTenantRequest.Id))
            {
                throw new DomainEntityNotFoundException("tenant_request_not_found",
                                                        $"Tenant request not found by id: {tTenantRequest} ");
            }

            _requests[tTenantRequest.Id] = tTenantRequest;
        }
コード例 #13
0
        public void AddTenantRequest(TenantRequest tTenantRequest)
        {
            var filter = Builders <PropertyModel> .Filter.And(
                Builders <PropertyModel> .Filter.Where(x => x.Id == tTenantRequest.Tenant.PropertyCode),
                Builders <PropertyModel> .Filter.ElemMatch(x => x.Tenants, c => c.UnitNumber == tTenantRequest.Tenant.UnitNumber));

            var update = Builders <PropertyModel> .Update.Push(x => x.Tenants[-1].Requests, _modelMapper.CopyFrom(tTenantRequest));

            _properties.FindOneAndUpdate(filter, update);
        }
コード例 #14
0
        public async Task CreateAndSendEmailAsync(TenantRequest tenantRequest, Worker worker)
        {
            await Task.CompletedTask;
            var email = _emailBuilderService.CreateTenantRequestEmail(tenantRequest, worker);

            if (email != null)
            {
                await _emailService.SendEmailAsync(email);
            }
        }
コード例 #15
0
        public static TenantRequestModel BuildModel(this TenantRequest tenantRequest)
        {
            return(new TenantRequestModel()
            {
                RequestCode = tenantRequest.Code,
                RequestStatus = tenantRequest.RequestStatus.ToString().SplitPascalCase(),
                DateCreated = tenantRequest.DateCreated,

                RequestTitle = tenantRequest.RequestTitle,
            });
        }
コード例 #16
0
        //----- Requests
        internal TenantRequest CopyFrom(TenantRequestTbl r)
        {
            var req =
                new TenantRequest(
                    CopyFrom(r.Tenant), r.Code, r.RequestStatus, r.DateCreated, r.ID)
            {
                RequestChanges = r.RequestChanges == null ? null : DeserializeObject(r.RequestChanges),

                ServiceWorkOrderCount = r.ServiceWorkOrderCount,
            };

            return(req);
        }
コード例 #17
0
        public TenantRequest CopyFrom(TenantRequestModel r)
        {
            var req =
                new TenantRequest(
                    CopyFrom(r.TenantModel), r.Code, r.RequestStatus, r.DateCreated, r.ID)
            {
                RequestChanges = DeserializeEvents(r.RequestChanges),

                ServiceWorkOrderCount = r.ServiceWorkOrderCount,
            };

            return(req);
        }
コード例 #18
0
    /// <summary>
    /// 获取租户列表
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public virtual async Task <PagedResult <TenantDto> > GetListAsync(TenantRequest input)
    {
        if (input.Sorting.IsNullOrWhiteSpace())
        {
            input.Sorting = nameof(Tenant.Name);
        }

        var count = await TenantRepository.GetCountAsync(input.Filter);

        var items = await TenantRepository.GetPagedListAsync(input.Page, input.PageSize, input.Sorting);

        return(new PagedResult <TenantDto>(count, items.MapTo <List <TenantDto> >()));
    }
コード例 #19
0
        public static TenancyDTO ToDTO(this TenantRequest tenant)
        {
            TenancyDTO dto = new TenancyDTO
            {
                PersonId       = tenant.PersonId,
                UserName       = tenant.UserName,
                From           = tenant.From,
                To             = tenant.To,
                UnitId         = tenant.UnitId,
                NumberOfPeople = tenant.NumberOfPeople
            };

            return(dto);
        }
コード例 #20
0
        internal TenantRequestTbl CopyFrom(TenantRequest req)
        {
            return(new TenantRequestTbl()
            {
                Code = req.Code,
                DateCreated = req.DateCreated,
                ID = req.Id,
                TenantID = req.Tenant.Id,

                RequestStatus = req.RequestStatus,
                RequestChanges = req.RequestChanges == null? null: SerializeObject(req.RequestChanges),
                ServiceWorkOrderCount = req.ServiceWorkOrderCount
            });
        }
コード例 #21
0
        //----- Requests
        internal TenantRequest CopyFrom(TenantRequestTbl r, TenantTbl tenantTbl, int requestCount, PropertyTbl propertyTbl)
        {
            TenantRequestStatusEnum reqStatus = (TenantRequestStatusEnum)Enum.Parse(typeof(TenantRequestStatusEnum), r.RequestStatus);
            var req =
                new TenantRequest(
                    CopyFrom(tenantTbl, requestCount, propertyTbl), r.Code, reqStatus, r.DateCreated, r.ID)
            {
                RequestChanges = r.RequestChanges == null ? null : DeserializeObject(r.RequestChanges),

                ServiceWorkOrderCount = r.ServiceWorkOrderCount,
            };

            return(req);
        }
コード例 #22
0
 internal TenantRequestTbl CopyFrom(TenantRequest req)
 {
     return(new TenantRequestTbl(req.TenantEmail, req.Code)
     {
         DateCreated = req.DateCreated,
         ID = req.Id,
         TenantID = req.Tenant.Id,
         PropertyCode = req.Tenant.Property.Code,
         UnitNumber = req.Tenant.UnitNumber,
         RequestStatus = req.RequestStatus.ToString( ),
         RequestChanges = req.RequestChanges == null? null: SerializeObject(req.RequestChanges),
         ServiceWorkOrderCount = req.ServiceWorkOrderCount
     });
 }
コード例 #23
0
        public TenantRequestModel  CopyFrom(TenantRequest req)
        {
            return(new TenantRequestModel()
            {
                Code = req.Code,
                DateCreated = req.DateCreated,
                ID = req.Id,
                TenantID = req.Tenant.Id,

                RequestStatus = req.RequestStatus,
                RequestChanges = SerializeEvents(req.RequestChanges),  //   req.RequestChanges == null ? null : SerializeObject(req.RequestChanges),

                ServiceWorkOrderCount = req.ServiceWorkOrderCount,
                TenantModel = CopyFrom(req.Tenant)
            });
        }
コード例 #24
0
        public async Task <IActionResult> Post([FromBody] TenantRequest request)
        {
            try
            {
                var tenantId = await _tenantService.Create(request);

                return(Created(HttpContext.Request.GetEncodedUrl(), tenantId));
            }
            catch (ArgumentNullException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (DuplicateNameException ex)
            {
                return(Conflict(ex.Message));
            }
        }
コード例 #25
0
        protected Worker GetWorkerDetails(TenantRequest tenantRequest)
        {
            Worker worker = null;

            if (tenantRequest.RequestStatus == TenantRequestStatusEnum.Scheduled ||
                tenantRequest.RequestStatus == TenantRequestStatusEnum.Done ||
                tenantRequest.RequestStatus == TenantRequestStatusEnum.Failed)
            {
                worker = _propertyRepository.GetWorkerByEmail(tenantRequest.WorkerEmail);
                if (worker == null)
                {
                    throw new DomainEntityNotFoundException("worker_not_found", "Worker not found");
                }
            }

            return(worker);
        }
コード例 #26
0
        public void UpdateTenantRequest(TenantRequest tTenantRequest)
        {
            var arrayFilters = new List <ArrayFilterDefinition>
            {
                new BsonDocumentArrayFilterDefinition <BsonDocument>(new BsonDocument("t.UnitNumber", tTenantRequest.Tenant.UnitNumber)),
                new BsonDocumentArrayFilterDefinition <BsonDocument>(new BsonDocument("r.Code", tTenantRequest.Code))
            };
            var updateOptions = new UpdateOptions {
                ArrayFilters = arrayFilters
            };

            _properties.UpdateOne(x => x.Id == tTenantRequest.Tenant.PropertyCode,
                                  Builders <PropertyModel> .Update
                                  .Set("Tenants.$[t].Requests.$[r].RequestStatus", tTenantRequest.RequestStatus)
                                  .Set("Tenants.$[t].Requests.$[r].RequestChanges", _modelMapper.SerializeEvents(tTenantRequest.RequestChanges))
                                  .Set("Tenants.$[t].Requests.$[r].ServiceWorkOrderCount", tTenantRequest.ServiceWorkOrderCount)
                                  , updateOptions
                                  );
        }
コード例 #27
0
        public async Task <IActionResult> Put(int id, [FromBody] TenantRequest request)
        {
            try
            {
                await _tenantService.UpdateByCompanyId(id, request);

                return(NoContent());
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (KeyNotFoundException ex)
            {
                return(NotFound(ex.Message));
            }
            catch (DuplicateNameException ex)
            {
                return(Conflict(ex.Message));
            }
        }
コード例 #28
0
        public async Task <Guid> Create(TenantRequest request)
        {
            if (request == null)
            {
                _logger.LogError($"[Create] Argument {nameof(request)} is null");
                throw new ArgumentNullException(nameof(request));
            }

            var tenants = await _tenantRepository.GetAsync();

            if (tenants.Any(x => x.TenantName.ToLower() == request.Name.ToLower()))
            {
                _logger.LogError($"[Create] Duplicate parameter: {nameof(request.Name)}");
                throw new DuplicateNameException();
            }

            var tenant = request.Adapt <Tenant>();

            tenant.CreatedOn = DateTime.UtcNow;
            return(await _tenantRepository.AddAsync(tenant));
        }
コード例 #29
0
        public static PropertyTenantRequestViewModel BuildViewModel(this TenantRequest tenantRequest)
        {
            return(new PropertyTenantRequestViewModel()
            {
                RequestCode = tenantRequest.Code,
                RequestStatus = tenantRequest.RequestStatus.ToString().SplitPascalCase(),
                DateCreated = tenantRequest.DateCreated,
                UnitNumber = tenantRequest.TenantUnit,
                RequestTitle = tenantRequest.RequestTitle,
                RequestDescription = tenantRequest.RequestDescription,

                ShowCloseButton = tenantRequest.RequestStatus == TenantRequestStatusEnum.Declined ||
                                  tenantRequest.RequestStatus == TenantRequestStatusEnum.Done,
                ShowScheduleRejectButtons = tenantRequest.RequestStatus == TenantRequestStatusEnum.Submitted,
                ShowScheduleButton = tenantRequest.RequestStatus == TenantRequestStatusEnum.Failed,
                ScheduledDate = DateTime.Now.Date,
                ShowReportButton = tenantRequest.RequestStatus == TenantRequestStatusEnum.Scheduled,
                PropertyCode = tenantRequest.Tenant.PropertyCode,
                History = tenantRequest.RequestChanges.BuildViewModel()
            });
        }
コード例 #30
0
 public void AddTenantRequest(TenantRequest tenantRequest)
 {
     _requests.Add(tenantRequest.Id, tenantRequest);
 }