Пример #1
0
        public tbCust InsertCust(tbCust cust)
        {
            DBCustManaging db = new DBCustManaging();

            var bus = new tbEntityBusiness();

            if (db.tbEntity.FirstOrDefault() == null)
            {
                bus.InsertEntity();
            }

            var geoLocation = this.getGeoLocation(cust.Address);

            cust.Location = new Tables.Location()
            {
                Lat = geoLocation.results[0].geometry.location.Lat,
                Lng = geoLocation.results[0].geometry.location.Lng
            };

            cust.LegalEntityId = bus.getClosestEntity(cust.Location.Lat, cust.Location.Lng);

            db.tbCust.Add(cust);
            db.SaveChanges();

            return(cust);
        }
Пример #2
0
        public IHttpActionResult PosttbCust(tbCust tbCust)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                tbCust = bus.InsertCust(tbCust);

                var custResult = new CustResult();
                custResult.CustId   = tbCust.CustId;
                custResult.Name     = tbCust.Name;
                custResult.Email    = tbCust.Email;
                custResult.Address  = tbCust.Address;
                custResult.Location = tbCust.Location;

                return(CreatedAtRoute("DefaultApi", new { id = custResult.CustId }, custResult));
            }
            catch (Exception ex)
            {
                return(Json("Por favor reveja os parâmetros digitados e envie novamente a solicitação"));
            }
        }
Пример #3
0
        public IHttpActionResult PuttbCust(int id, tbCust tbCust)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tbCust.CustId)
            {
                return(Json("Ids informados não conferem. Por favor, digite um id válido"));
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!tbCustExists(id))
                {
                    return(Json("Id não encontrado. Por favor, digite um id válido"));
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #4
0
        public IHttpActionResult GettbCust(int id)
        {
            tbCust tbCust = db.tbCust.Find(id);

            if (tbCust == null)
            {
                return(Json("Id não encontrado. Por favor, digite um id válido"));
            }

            return(Ok(tbCust));
        }
Пример #5
0
        public IHttpActionResult DeletetbCust(int id)
        {
            tbCust tbCust = db.tbCust.Find(id);

            if (tbCust == null)
            {
                return(Json("Id não encontrado. Por favor, digite um id válido"));
            }

            db.tbCust.Remove(tbCust);
            db.SaveChanges();

            return(Ok("Cliente removido com sucesso"));
        }