public void UpdateValidItemTest()
        {
            var timeZoneService = new TimeZoneService(new MockTimeZoneRepository());
            var item            = GetMockTimeZone(1);

            timeZoneService.Add(item);
            item.Name = "updated";
            timeZoneService.Update(item);

            Assert.AreEqual(item.Name, timeZoneService.GetByID(1).Name);
        }
Exemplo n.º 2
0
        // PUT api/<controller>/5
        public IHttpActionResult Put(int id, [FromBody] TimeZoneDTO item)
        {
            try
            {
                var         timeZoneService = new TimeZoneService(new TimeZoneRepository());
                TimeZoneDTO timeZone        = timeZoneService.GetByID(id);

                if (!User.IsInRole("Admin") && (item.Owner != User.Identity.Name))
                {
                    return(Unauthorized());
                }

                item.ID = id;
                timeZoneService.Update(item);

                return(Ok(HttpStatusCode.NoContent));
            }
            catch (Exception e)
            {
                return(InternalServerError(e));
            }
        }