Пример #1
0
        public IHttpActionResult Post(OrganizationBindingModel model)
        {
            //validation
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var org = new Organization
            {
                Id = Guid.NewGuid(),
                Name = model.Name,
                Description = model.Description,
                ShortName = model.ShortName,
                Address = model.Address,
                Phone = model.Phone,
                Email = model.Email,
                Website = model.Website,
                Created = DateTime.Now
            };

            _uow.Organizations.Add(org);
            _uow.Commit();

            return Ok(org);
        }
Пример #2
0
        public IHttpActionResult PutOrg(Guid id, OrganizationBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

            var item = _uow.Organizations.Get(id);

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

            item.Name = model.Name;
            item.Description = model.Description;
            item.ShortName = model.ShortName;
            item.Address = model.Address;
            item.Email = model.Email;
            item.Phone = model.Phone;
            item.Website = model.Website;
            item.LastUpdated = DateTime.Now;

            try
            {
                _uow.Commit();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }

            return StatusCode(HttpStatusCode.NoContent);
        }