public IResult Add(Maintenance maintenance)
 {
     _maintenanceDal.Add(maintenance);
     return(new SuccessResult(Messages.Added));
 }
示例#2
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);
        }