示例#1
0
        public IHttpActionResult Edit(TjCustomer model)
        {
            var response = ResponseModelFactory.CreateInstance;

            using (_dbContext)
            {
                var entity = _dbContext.TjCustomers.FirstOrDefault(x => x.Id == model.Id);
                if (entity == null)
                {
                    response.SetFailed("该客户不存在");
                    return(Ok(response));
                }

                entity.Name     = model.Name;
                entity.Phone    = model.Phone;
                entity.Email    = model.Email;
                entity.Company  = model.Company;
                entity.Region   = model.Region;
                entity.Location = model.Location;
                entity.Industry = model.Industry;
                entity.Owner    = AuthContextService.CurrentUser.UserId;
                _dbContext.SaveChanges();
                response = ResponseModelFactory.CreateInstance;
                return(Ok(response));
            }
        }
示例#2
0
        public IHttpActionResult PostTjCustomer(TjCustomer tjCustomer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.TjCustomers.Add(tjCustomer);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (TjCustomerExists(tjCustomer.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = tjCustomer.Id }, tjCustomer));
        }
示例#3
0
        public IHttpActionResult PutTjCustomer(int id, TjCustomer tjCustomer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#4
0
        public IHttpActionResult GetTjCustomer(int id)
        {
            TjCustomer tjCustomer = db.TjCustomers.Find(id);

            if (tjCustomer == null)
            {
                return(NotFound());
            }

            return(Ok(tjCustomer));
        }
示例#5
0
        public IHttpActionResult Create(TjCustomer customer)
        {
            var response = ResponseModelFactory.CreateInstance;

            using (_dbContext)
            {
                customer.Owner = AuthContextService.CurrentUser.UserId;
                _dbContext.TjCustomers.Add(customer);
                _dbContext.SaveChanges();
            }

            response.SetSuccess();
            return(Ok(response));
        }
示例#6
0
        public IHttpActionResult DeleteTjCustomer(int id)
        {
            TjCustomer tjCustomer = db.TjCustomers.Find(id);

            if (tjCustomer == null)
            {
                return(NotFound());
            }

            db.TjCustomers.Remove(tjCustomer);
            db.SaveChanges();

            return(Ok(tjCustomer));
        }