示例#1
0
        public IHttpActionResult PutCustomer(short id, Customer customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != customer.CustomerID)
            {
                return(BadRequest());
            }

            db.Entry(customer).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#2
0
        public IHttpActionResult Put(CustomerViewModel customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Not a valid model"));
            }

            using (var ctx = new CustomerConnection())
            {
                var existingCustomer = ctx.Customers.Where(s => s.CustomerId == customer.CostumerId)
                                       .FirstOrDefault <Customer>();

                if (existingCustomer != null)
                {
                    existingCustomer.Name     = customer.Name;
                    existingCustomer.EmailId  = customer.EmailId;
                    existingCustomer.Address  = customer.Address;
                    existingCustomer.MobileNo = customer.MobileNo;

                    ctx.SaveChanges();
                }
                else
                {
                    return(NotFound());
                }
            }

            return(Ok());
        }
示例#3
0
        public IHttpActionResult Post()
        {
            using (var ctx = new CustomerConnection())
            {
                ctx.Customers.Add(new Customer()
                {
                    Name     = "Eduardo",
                    Address  = "Rua Das Margaridas",
                    EmailId  = "@google.com",
                    MobileNo = "1199993333",
                    Birthday = DateTime.Now
                });

                ctx.SaveChanges();
            }

            return(Ok());
        }
示例#4
0
        public IHttpActionResult Delete(int id)
        {
            if (id <= 0)
            {
                return(BadRequest("Not a valid student id"));
            }

            using (var ctx = new CustomerConnection())
            {
                var customer = ctx.Customers
                               .Where(s => s.CustomerId == id)
                               .FirstOrDefault();

                ctx.Entry(customer).State = System.Data.Entity.EntityState.Deleted;
                ctx.SaveChanges();
            }

            return(Ok());
        }