public override async Task <ActionResult <RequestDto> > Create(RequestDto value, CancellationToken cancellationToken)
        {
            var workflow = _workflowService.Queryable.FirstOrDefault(r => r.RequestTypeId == value.RequestTypeId);

            if (workflow is null)
            {
                throw new Exception("not found workflow of this request");
            }
            value.IsDone         = false;
            value.IsSuccess      = false;
            value.WorkflowId     = workflow.Id;
            value.TrackingNumber = _hasher.CalculateTimeHash("TrackingNumber" + Guid.NewGuid());
            value.DateCreated    = DateTime.UtcNow;

            if (value.PropertyId.HasValue)
            {
                var property = _propertyService.Queryable.FirstOrDefault(r => r.Id == value.PropertyId.Value);
                if (property is null)
                {
                    throw new Exception("not found property of this request");
                }
                value.Commission = property.Commission;
            }

            var res = await ModelService.CreateByDtoAsync(value, cancellationToken);

            await _signaler.Signal(_userAccountService.GetAll(u => u.AgentUserAccount.Any(a => a.IsResponsible))
                                   .Select(u => u.Id).ToList(), nameof(Request), "A new request has arrived");

            return(res);
        }
        public async Task <ActionResult <RequestDto> > CreateRequestSandBox([FromBody] RequestDto request, CancellationToken cancellationToken)
        {
            request.TrackingNumber = _hasher.CalculateTimeHash("TrackingNumber" + Guid.NewGuid());
            request.DateCreated    = DateTime.Now;
            var res = await ModelService.CreateByDtoAsync(request, cancellationToken);

            await _signaler.Signal(_userAccountService.GetAll(u => u.AgentUserAccount.Any(a => a.IsResponsible))
                                   .Select(u => u.Id).ToList(), nameof(Request), "A new request has arrived");

            return(res);
        }
Esempio n. 3
0
        public override async Task <ActionResult <PropertyFloorPlanDto> > Create(PropertyFloorPlanDto value, CancellationToken cancellationToken)
        {
            var res = await ModelService.CreateByDtoAsync(value, cancellationToken);

            var property = await _propertyService.GetAsync(value.PropertyId, cancellationToken);

            if (property != null && property.IsPublished)
            {
                property.IsPublished = false;
                await _propertyService.UpdateAsync(property, cancellationToken);
            }

            return(res);
        }
        public override async Task <ActionResult <PropertyPriceDto> > Create(PropertyPriceDto value, CancellationToken cancellationToken)
        {
            var unit = await _priceScaleUnitService.GetAsync(value.PriceScaleUnitId, cancellationToken);

            if (unit is null)
            {
                throw new Exception("not found price scale unit");
            }

            value.CalculatedPriceUnit = value.Price * unit.Scale;
            var res = await ModelService.CreateByDtoAsync(value, cancellationToken);

            return(res);
        }
        public override async Task <ActionResult <PropertyLocationDto> > Create(PropertyLocationDto value, CancellationToken cancellationToken)
        {
            var countryItem = _countryService.AsQueryable(r => r.Name == value.Country).FirstOrDefault();

            if (countryItem == null)
            {
                countryItem = _countryService.Create(new Country
                {
                    CurrencyId = 11,
                    Name       = value.Country,
                });
            }

            var regionItem = _regionService.AsQueryable(r => r.CountryId == countryItem.Id && r.Name == value.Region).FirstOrDefault();

            if (regionItem == null)
            {
                regionItem = _regionService.Create(new Region
                {
                    CountryId = countryItem.Id,
                    Name      = value.Region,
                });
            }

            var cityItem = _cityService.AsQueryable(r => r.RegionId == regionItem.Id && r.Name == value.City).FirstOrDefault();

            if (cityItem == null)
            {
                cityItem = _cityService.Create(new City
                {
                    RegionId = regionItem.Id,
                    Name     = value.City,
                });
            }
            value.CityId = cityItem.Id;

            var res = await ModelService.CreateByDtoAsync(value, cancellationToken);

            var property = await _propertyService.GetAsync(value.PropertyId, cancellationToken);

            if (property != null && property.IsPublished)
            {
                property.IsPublished = false;
                await _propertyService.UpdateAsync(property, cancellationToken);
            }

            return(res);
        }
        public async Task <ActionResult <ImportantPlaceTypeDto> > UploadAndCreate(CancellationToken cancellationToken)
        {
            var file = Request.Form.Files[0];

            if (file == null || file.Length <= 0)
            {
                throw new AppException("file is not set");
            }
            var placeTypeDto = new ImportantPlaceTypeDto
            {
                Name     = Request.Form["Name"],
                TypeIcon = await _uploadHelperService
                           .ImageService.GetImageBytes(file.OpenReadStream(), cancellationToken)
            };

            return(await ModelService.CreateByDtoAsync(placeTypeDto, cancellationToken));
        }
Esempio n. 7
0
        public override async Task <ActionResult <RequestStateDto> > Create(RequestStateDto value, CancellationToken cancellationToken)
        {
            using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    var req = _requestService.AsQueryable(r => r.Id == value.RequestId).Include("PropertyNavigation").Include("PropertyNavigation.PropertyPrice").FirstOrDefault();
                    if (req is null)
                    {
                        throw new Exception("not found request");
                    }

                    var wsLatest = _requestStateService.AsQueryable(r => r.RequestId == value.RequestId).Include("WorkflowStep").OrderByDescending(r => r.Id).FirstOrDefault();
                    if (wsLatest is null)
                    {
                        throw new Exception("not found latest state");
                    }

                    var ws = _workflowStepService.Get(value.WorkflowStepId);
                    if (ws is null)
                    {
                        throw new Exception("not found workflowId");
                    }

                    if (!wsLatest.WorkflowStep.IsFinish)
                    {
                        req.IsDone = value.IsDone;
                    }

                    if (ws.IsFinish)
                    {
                        req.IsDone    = true;
                        req.IsSuccess = true;

                        if (req.UserAccountIdShared.HasValue)
                        {
                            var com = new Commission
                            {
                                Id = value.RequestId,
                                CommissionPercent = req.Commission.GetValueOrDefault(0),
                                Amount            = (req.PropertyNavigation.PropertyPrice.CalculatedPriceUnit * req.Commission.GetValueOrDefault(0)) / 100,
                                DateCreated       = DateTime.UtcNow,
                            };
                            var commissionResult = await _commissionService.CreateAsync(com, cancellationToken);
                        }
                    }

                    var newReq = _requestService.Update(req);

                    var res = await ModelService.CreateByDtoAsync(value, cancellationToken);

                    scope.Complete();
                    return(res);
                }
                catch (Exception ex)
                {
                    scope.Dispose();
                    throw new Exception(ex.Message);
                }
            }
        }