Ejemplo n.º 1
0
        public async Task<int> CreateAsync(Saying saying)
        {
            _context.Sayings.Add(saying);

            await _context.SaveChangesAsync();

            return saying.Id;
        }
Ejemplo n.º 2
0
        public ValidationMessages Validate(Saying saying)
        {
            var validations = new ValidationMessages();

            // Probably will move this logic into sayingService - a Validate method
            if (saying.SageId == 0) 
            {
                // eg "saying.sageId"
                var fieldName = ValidationHelpers.GetFieldName(saying, x => x.SageId);
                validations.AddError(fieldName, "Please select a sage.");
            }

            return validations;
        }
Ejemplo n.º 3
0
        public async Task<IHttpActionResult> Post(Saying saying)
        {
            if (!ModelState.IsValid)
            {
                return this.BadRequest(ModelState.ToValidationMessages());
            }

            // Perform service validations
            var serviceValidations = _sayingService.Validate(saying);
            if (serviceValidations.HasErrors())
                return this.BadRequest(serviceValidations.WithCamelCaseKeys());

            if (saying.Id > 0)
            {
                await _sayingService.UpdateAsync(saying);
                return Ok();
            }

            var sayingId = await _sayingService.CreateAsync(saying);
            return Ok(sayingId);
        }
Ejemplo n.º 4
0
 public async Task UpdateAsync(Saying saying)
 {
     await _sayingCommand.UpdateAsync(saying);
 }
Ejemplo n.º 5
0
 public async Task<int> CreateAsync(Saying saying)
 {
     return await _sayingCommand.CreateAsync(saying);
 }
Ejemplo n.º 6
0
        public async Task UpdateAsync(Saying saying)
        {
            _context.Entry(saying).State = EntityState.Modified;

            await _context.SaveChangesAsync();
        }