Beispiel #1
0
        public async Task <string> SetAppCenterDetailsAsync(BL_AppCenterDetails bl_dto)
        {
            var utcNow = DateTimeOffset.UtcNow;

            //Read Existing one
            var existingItem = await _repo.GetAppCenterDeviceDetails_DeviceId(bl_dto.DeviceId);

            if (existingItem == null)
            {
                existingItem = new AppCenterDeviceDetail
                {
                    DTCreated = utcNow,
                    DeviceId  = bl_dto.DeviceId
                };
            }

            //Map incoming data to existing entity (need to be mapped this way to not overwrite new properties not part of incoming BL_UserProfile)
            existingItem.DTLastUpdated  = utcNow;
            existingItem.TypeOfDeviceOs = map.From(bl_dto.TypeOfOs);
            existingItem.UserprofileId  = bl_dto.UserprofileId;

            //Validate - done after mapping to ensure the mapping logic not broken
            if (validator.CanSetAppCenterDetails(existingItem, out var validationResult))
            {
                var idUpdatedOrCreated = await _repo.SetAppCenterDeviceDetailsAsync(existingItem);

                return(idUpdatedOrCreated);
            }
            else
            {
                throw new BusinessLogicException(validationResult);
            }
        }
Beispiel #2
0
        public async Task <IActionResult> Post([FromBody] AppCenterRequestInfo request)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(this.ApiErrorMessage400BadRequest(ModelState));
                }

                var jwtPayloadInfo = this.GetJwtPayloadInfo();
                var userProfileId  = await _bl.GetCachedUserId_byExternalReferenceIdAsync(jwtPayloadInfo.ExtReferenceId);

                if (userProfileId == null)
                {
                    return(this.ApiErrorMessage400BadRequestUserIdInTokenNotFound(jwtPayloadInfo.ExtReferenceId));
                }

                var bl_dto = new BL_AppCenterDetails
                {
                    DeviceId      = request.DeviceId,
                    DTUpdated     = DateTimeOffset.MinValue,
                    TypeOfOs      = EnumMapper.From(request.TypeDeviceOs),
                    UserprofileId = userProfileId
                };

                await _bl.SetAppCenterDetailsAsync(bl_dto);

                return(this.ApiPutMessage204NotContent());
            }
            catch (BusinessLogicException ex)
            {
                HttpContext.Items.Add("ex", ex); //For instrumentation
                return(this.ApiErrorMessage400BadRequest(ex));
            }
            catch (Exception ex)
            {
                HttpContext.Items.Add("ex", ex); //For instrumentation
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }