Ejemplo n.º 1
0
        public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = "sperrov1/pendingsponsor")] HttpRequestMessage req,
                                              [Inject(typeof(ISponsorRepository))] ISponsorRepository sponsorRepository,
                                              TraceWriter log)
        {
            log.Info("C# HTTP trigger function processed a request.");

            string jsonContent = req.Content.ReadAsStringAsync().Result;

            Sponsor sponsor = JsonConvert.DeserializeObject <Sponsor>(jsonContent);

            sponsor.Status = SponsorStatus.Pending;

            sponsorRepository.Create(sponsor);

            // Fetching the name from the path parameter in the request URL
            return(req.CreateResponse(HttpStatusCode.OK));
        }
Ejemplo n.º 2
0
        public OperationResult Create(CreateSponsor command)
        {
            var operation = new OperationResult();

            if (_sponsorRepository.Exist(x => x.Name == command.Name))
            {
                return(operation.Failed(ApplicationMessages.DuplicatedRecord));
            }

            var ImageFolderName = Tools.ToFolderName(this.GetType().Name);
            var ImagePath       = $"{ImageFolderName}/{command.Name}";
            var imageFileName   = _fileUploader.Upload(command.Image, ImagePath);

            var sponsor = new Sponsor(command.Name, command.Tel, imageFileName, command.ImageAlt,
                                      command.ImageTitle, command.IsVisible, command.Bio);

            _sponsorRepository.Create(sponsor);
            _sponsorRepository.SaveChanges();
            return(operation.Succedded());
        }