Пример #1
0
        public void CanDeleteBusiness()
        {
            var adminUser = new User
            {
                Id           = Guid.NewGuid(),
                FirstName    = "Ryan",
                LastName     = "Reynolds",
                EmailAddress = "*****@*****.**",
                UserName     = "******"
            };
            var business = new Business
            {
                Name        = "Green lanterns busines",
                Description = "Description of business",
                Email       = "*****@*****.**",
                Phone       = "123456",
                Users       = new List <User> {
                    adminUser
                }
            };

            var businessId = _orgRepo.Insert(business);

            Assert.IsNotNull(businessId);

            _orgRepo.Delete(businessId);

            Assert.IsNull(_orgRepo.GetById(businessId));
        }
        public async Task <IActionResult> AddVideoForUser(int businessId,
                                                          [FromForm] VideoForCreationDto videoForCreationDto)
        {
            var businessFromRepo = await _repo.GetBusiness(businessId);

            if (businessFromRepo.UserId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }


            var file = videoForCreationDto.File;

            var uploadResult = new VideoUploadResult();

            if (file.Length > 0)
            {
                using (var stream = file.OpenReadStream())
                {
                    var uploadParams = new VideoUploadParams
                    {
                        File = new FileDescription(file.Name, stream)
                    };

                    uploadResult = _cloudinary.Upload(uploadParams);
                }
            }

            if (businessFromRepo.Video != null && businessFromRepo.Video.PublicId != null)
            {
                var deleteParams = new DeletionParams(businessFromRepo.Video.PublicId)
                {
                    ResourceType = ResourceType.Video
                };

                var result = _cloudinary.Destroy(deleteParams);

                if (result.Result == "ok")
                {
                    _repo.Delete(businessFromRepo.Video);
                }
            }

            videoForCreationDto.Url      = uploadResult.Uri.ToString();
            videoForCreationDto.PublicId = uploadResult.PublicId;

            var video = _mapper.Map <VideoModel>(videoForCreationDto);

            businessFromRepo.Video = video;

            if (await _repo.SaveAll())
            {
                var videoToReturn = _mapper.Map <VideoForReturnDto>(video);
                return(CreatedAtRoute("GetVideo", new { id = video.Id }, videoToReturn));
            }

            return(BadRequest("Cloud not add the video"));
        }
        public async Task <IActionResult> BusinessUpdate([FromBody] CmsPostWebHookApiModel model)
        {
            var(isValid, modelErrorMessage, postId) = IsModelValid(model);
            if (!isValid)
            {
                return(BadRequest(modelErrorMessage));
            }

            var webHookTypeName = HeaderType();

            if (string.IsNullOrEmpty(webHookTypeName) || webHookTypeName != "post_update")
            {
                return(BadRequest("no webhook name provided."));
            }

            // if "trashed" remove from elastic and cache
            if (model.post.post_status == "trash")
            {
                var removeSuccessful = await _businessRepository.Delete(postId);

                if (!removeSuccessful)
                {
                    _logger.LogError("Failed to delete business with id: {PostId} in elasticsearch.", postId);
                    return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to delete business."));
                }
                return(NoContent());
            }

            var cityId = StringHelper.ReturnId(model.post_meta?.city?.FirstOrDefault());
            var region = await GetRegionFromId(cityId);

            var business_path = CmsVariable.SingleBusinessRegion ? "global_business" : region.Businesses_api_path;

            var cmsBusiness = await _cmsApiProxy.GetBusiness(postId, business_path);


            var elasticBusiness = await MapToElasticModel(cmsBusiness);

            var successful = await _businessRepository.Update(elasticBusiness);

            if (!successful)
            {
                _logger.LogError("Failed to update business with id: {PostId} in elasticsearch.", postId);
                return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to update business."));
            }

            _logger.LogInformation("Business with id {PostId} updated in elasticsearch successfully.", postId);

            return(Ok());
        }
Пример #4
0
 private async Task TearDownTests()
 {
     userList.ForEach(async user => await userStore.DeleteAsync(user));
     businessList.ForEach(bus => _orgRepo.Delete(bus.Id));
     userList     = null;
     businessList = null;
 }
Пример #5
0
        public async Task <IActionResult> DeletePhoto(int businessId, int id)
        {
            var businessFromRepo = await _repo.GetBusiness(businessId);

            if (businessFromRepo.UserId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            if (!businessFromRepo.Photos.Any(p => p.Id == id))
            {
                return(Unauthorized());
            }

            var photoFromRepo = await _repo.GetPhoto(id);

            if (photoFromRepo.IsMain)
            {
                return(BadRequest("You cannot delete your main photo"));
            }

            if (photoFromRepo.PublicId != null)
            {
                var deleteParams = new DeletionParams(photoFromRepo.PublicId);

                var result = _cloudinary.Destroy(deleteParams);

                if (result.Result == "ok")
                {
                    _repo.Delete(photoFromRepo);
                }
            }

            if (photoFromRepo.PublicId == null)
            {
                _repo.Delete(photoFromRepo);
            }

            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Failed to delete the photo"));
        }
Пример #6
0
        /// <summary>
        /// 删除客户端打印机
        /// </summary>
        /// <param name="id"></param>
        /// <param name="service"></param>
        /// <returns></returns>
        public IActionResult DeletePrinter(int id, [FromServices] IBusinessRepository service)
        {
            var result = service.Delete(new ClientPrinter {
                ID = id
            });

            return(Json(new JsonData {
                Success = result > 0
            }));
        }
Пример #7
0
 public bool Delete(string id)
 {
     return(_businessRepository.Delete(id));
 }
Пример #8
0
 public int Delete(string sqlQuery, DynamicParameters param, CommandType commandType)
 {
     return(_businessRepository.Delete(sqlQuery, param, commandType));
 }
Пример #9
0
 public IActionResult Delete(string id)
 {
     businessRepo.Delete(id);
     return(RedirectToAction("Index"));
 }