Ejemplo n.º 1
0
        public Share AddShare(ShareToAdd share)
        {
            if (share == null || share.Name == null || share.Name.Length == 0 || share.Name.Length > 100 || share.Price == 0M)
            {
                return(null);
            }

            return(sharesRepository.AddShare(share));
        }
Ejemplo n.º 2
0
        public Share AddShare(ShareToAdd share)
        {
            var newShare = context.Shares.Add(new Share
            {
                Name  = share.Name,
                Price = share.Price,
            });

            context.SaveChanges();

            return(newShare);
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <string> > Add([FromBody] ShareToAdd share)
        {
            var newShare = sharesService.AddShare(share);

            if (newShare != null)
            {
                return(new ActionResult <string>("New record added"));
            }
            else
            {
                return(new ActionResult <string>("Can't add record"));
            }
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <string> > Post([FromBody] ShareToAdd share)
        {
            Share newShare = null;

            if (share == null || share.Price == 0)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            newShare = contextProvider.Shares.Add
                           (new Share()
            {
                Name = share.Name, Price = share.Price
            });

            if (newShare != null)
            {
                try
                {
                    contextProvider.SaveChanges();
                }
                catch (Exception)
                {
                    return(BadRequest());
                }

                return("Share added");
            }
            else
            {
                return(BadRequest());
            }
        }