Ejemplo n.º 1
0
        public async Task <PopularResult <string> > UpdateAsync(MaintenanceDto dto)
        {
            var result = new PopularResult <string>();

            dto.Vehicle = null;
            var maintenance = ObjectMapper.Map <MaintenanceDto, MaintenanceEntity>(dto);
            await _maintenanceRepository.UpdateAsync(maintenance);

            result.Success("更新成功");
            return(result);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([FromBody] MaintenanceDto maintenanceDto)
        {
            var maintenance = mapper.Map <Maintenance>(maintenanceDto);
            await maintenanceRepository.Insert(maintenance);

            var vehicle = await vehicleRepository.GetById(maintenance.VehicleId);

            vehicle.Cost += maintenance.Cost;
            await vehicleRepository.Update(vehicle);

            return(Ok(maintenance.Id));
        }
Ejemplo n.º 3
0
        public IActionResult Edit(MaintenanceDto maintenanceDto)
        {
            var response = new ResponseViewModel();

            response = _maintenanceService.Update(maintenanceDto);

            if (!response.IsSuccess)
            {
                return(BadRequest(response));
            }

            return(Ok(response));
        }
Ejemplo n.º 4
0
        public async Task <PopularResult <string> > InsertAsync(MaintenanceDto dto)
        {
            var result      = new PopularResult <string>();
            var entity      = ObjectMapper.Map <MaintenanceDto, MaintenanceEntity>(dto);
            var maintenance = await _maintenanceRepository.InsertAsync(entity);

            if (maintenance == null)
            {
                result.Failed("添加失败");
                return(result);
            }
            result.Success("添加成功");
            return(result);
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> MaintenanceGet(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "maintenance/{id}")] MaintenanceDto request,
            string id,
            [CosmosDB(ConnectionStringSetting = "CosmosDBConnection")] DocumentClient client,
            ILogger log,
            ClaimsPrincipal principal,
            CancellationToken token
            )
        {
            var uri     = UriFactory.CreateDocumentUri("MaintenanceDB", "VehicleMaintenance", id);
            var options = new RequestOptions {
                PartitionKey = new PartitionKey(_b2cHelper.GetOid(principal).ToString())
            };
            var documentResponse = await client.ReadDocumentAsync <MaintenanceModel>(uri, options, token);

            var maintenance = _mapper.Map <MaintenanceDto>(documentResponse.Document);

            log.LogInformation($"Got maintenance id {id} for user {_b2cHelper.GetOid(principal)}");
            return(new OkObjectResult(maintenance));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Update(int id, [FromBody] MaintenanceDto maintenanceDto)
        {
            var oldMaintenance = await maintenanceRepository.GetById(id);

            if (oldMaintenance == null)
            {
                return(NotFound("No such maintenance."));
            }

            var maintenance = mapper.Map <Maintenance>(maintenanceDto);
            await maintenanceRepository.Update(maintenance);

            var vehicle = await vehicleRepository.GetById(maintenance.VehicleId);

            var deltaCost = maintenance.Cost - oldMaintenance.Cost;

            vehicle.Cost += deltaCost;
            await vehicleRepository.Update(vehicle);

            return(Ok());
        }
Ejemplo n.º 7
0
        public async Task MaintenanceUpsert(
            [HttpTrigger(AuthorizationLevel.Anonymous, "put", Route = "maintenance")] MaintenanceDto request,
            [CosmosDB(ConnectionStringSetting = "CosmosDBConnection")] DocumentClient client,
            ILogger log,
            ClaimsPrincipal principal
            )
        {
            var uri     = UriFactory.CreateDocumentCollectionUri("MaintenanceDB", "VehicleMaintenance");
            var options = new RequestOptions {
                PartitionKey = new PartitionKey(_b2cHelper.GetOid(principal).ToString())
            };
            var maintenance = _mapper.Map <MaintenanceModel>(request);

            if (maintenance.id == Guid.Empty)
            {
                maintenance.id = Guid.NewGuid();
            }
            maintenance.UserId = _b2cHelper.GetOid(principal);
            maintenance.Type   = VehicleMaintenanceTypes.Maintenance;
            await client.UpsertDocumentAsync(uri, maintenance, options);

            log.LogInformation($"Upserting maintenance id {maintenance.id} for user {_b2cHelper.GetOid(principal)}");
        }
Ejemplo n.º 8
0
        public ResponseViewModel Get(int id)
        {
            var response = new ResponseViewModel();

            var maintenance = _maintenanceDal.GetMaintenance(p => p.Id == id);

            if (maintenance == null)
            {
                response.IsSuccess = false;
                response.Message   = "Maintenance bulunamadı.";
                return(response);
            }

            var maintenanceDto = new MaintenanceDto()
            {
                Id                = maintenance.Id,
                VehicleId         = maintenance.VehicleId,
                UserId            = maintenance.UserId,
                Description       = maintenance.Description,
                PictureGroupId    = maintenance.PictureGroupId,
                ExpectedTimeToFix = maintenance.ExpectedTimeToFix,
                ResponsibleUserId = maintenance.ResponsibleUserId,
                LocationLatitude  = maintenance.LocationLatitude,
                LocationLongitude = maintenance.LocationLongitude,
                StatusId          = maintenance.StatusId,
                CreateDate        = maintenance.CreateDate,
                CreatedBy         = maintenance.CreatedBy,
                ModifiedBy        = maintenance.ModifiedBy,
                ModifyDate        = maintenance.ModifyDate,
                IsDeleted         = maintenance.IsDeleted
            };

            response.Data = maintenanceDto;

            return(response);
        }
Ejemplo n.º 9
0
        public ResponseViewModel Add(MaintenanceDto maintenanceDto)
        {
            var response = new ResponseViewModel();

            var vehicleId = IsVehicleHave(maintenanceDto.VehicleId);

            if (!vehicleId)
            {
                response.IsSuccess = false;
                response.Message   = "VehicleID Vehicle tablosunda bulunamadı ";

                return(response);
            }

            var userId = IsUserHave(maintenanceDto.UserId);

            if (!userId)
            {
                response.IsSuccess = false;
                response.Message   = "UserID User tablosunda bulunamadı ";

                return(response);
            }

            if (maintenanceDto.PictureGroupId != null)
            {
                var pictureGroupId = IsPictureGroupHave((int)maintenanceDto.PictureGroupId);

                if (!pictureGroupId)
                {
                    response.IsSuccess = false;
                    response.Message   = "pictureGroupId pictureGroup tablosunda bulunamadı ";

                    return(response);
                }
            }

            if (maintenanceDto.ResponsibleUserId != null)
            {
                var responsibleUserId = IsUserHave((int)maintenanceDto.ResponsibleUserId);
                if (!responsibleUserId)
                {
                    response.IsSuccess = false;
                    response.Message   = "responsibleUserId User tablosunda bulunamadı ";

                    return(response);
                }
            }

            var statusId = IsStatusHave(maintenanceDto.StatusId);

            if (!statusId)
            {
                response.IsSuccess = false;
                response.Message   = "statusId Status tablosunda bulunamadı ";

                return(response);
            }

            if (maintenanceDto.CreatedBy != null)
            {
                var createdBy = IsUserHave((int)maintenanceDto.CreatedBy);
                if (!createdBy)
                {
                    response.IsSuccess = false;
                    response.Message   = "createdBy User tablosunda bulunamadı ";

                    return(response);
                }
            }


            var maintenance = new Maintenance()
            {
                VehicleId         = maintenanceDto.VehicleId,
                UserId            = maintenanceDto.UserId,
                Description       = maintenanceDto.Description,
                PictureGroupId    = maintenanceDto.PictureGroupId,
                ExpectedTimeToFix = maintenanceDto.ExpectedTimeToFix,
                ResponsibleUserId = maintenanceDto.ResponsibleUserId,
                LocationLongitude = maintenanceDto.LocationLongitude,
                LocationLatitude  = maintenanceDto.LocationLatitude,
                StatusId          = maintenanceDto.StatusId,
                CreateDate        = DateTime.Now,
                CreatedBy         = maintenanceDto.CreatedBy,
            };

            _maintenanceDal.Add(maintenance);
            var saving = _maintenanceDal.SaveChanges();

            if (!saving)
            {
                response.IsSuccess = false;
                response.Message   = "Maintenance kaydedilirken bir hata oluştu";
                response.Data      = maintenance;
            }

            response.Data = "Id : " + maintenance.Id;

            return(response);
        }
Ejemplo n.º 10
0
 public async Task <PopularResult <string> > UpdateAsync([FromBody] MaintenanceDto dto)
 {
     return(await _maintenanceService.UpdateAsync(dto));
 }
Ejemplo n.º 11
0
 public async Task <PopularResult <string> > InsertAsync([FromBody] MaintenanceDto dto)
 {
     dto.Creator    = LoginUser.Id;
     dto.CreateTime = LoginUser.SysteDate;
     return(await _maintenanceService.InsertAsync(dto));
 }