Exemplo n.º 1
0
        public async Task <IActionResult> PutPartner([FromRoute] string id, [FromBody] PartnerVm partnerVm)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != partnerVm.Id)
            {
                return(BadRequest());
            }

            if (!string.IsNullOrEmpty(partnerVm.Image64))
            {
                _SaveLogo(partnerVm.Image64, partnerVm.Id);
            }

            var partner = partnerVm.ToBase();

            partner.UpdatedDate           = DateTime.UtcNow;
            _context.Entry(partner).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PartnerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PostPartner([FromBody] PartnerVm partnerVm)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (string.IsNullOrEmpty(partnerVm.Image64))
            {
                return(BadRequest(new
                {
                    message = "Please set an image."
                }));
            }

            _SaveLogo(partnerVm.Image64, partnerVm.Id);

            var partner = partnerVm.ToBase();

            _context.Partners.Add(partner);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetPartner", new { id = partner.Id }, partner));
        }