Пример #1
0
 public IActionResult PostTimezone(ApplicationDbContext dbContext, [FromBody] UserDefinedTimeZone timeZone)
 {
     timeZone.Id      = Guid.NewGuid().ToString();
     timeZone.OwnerId = User.FindFirst("UserId").Value;
     timeZone.Owner   = User.FindFirst(JwtRegisteredClaimNames.Sub).Value;
     dbContext.TimeZones.Add(timeZone);
     dbContext.SaveChanges();
     return(Ok(timeZone));
 }
Пример #2
0
        public async Task <IActionResult> PutTimezone(ApplicationDbContext dbContext, string id, [FromBody] UserDefinedTimeZone timeZone)
        {
            var record = dbContext.TimeZones.Find(id);

            if (record != null)
            {
                var authResult = await _authorizationService.AuthorizeAsync(User, record, "EditPolicy");

                if (!authResult.Succeeded)
                {
                    return(Unauthorized());
                }

                record.Name      = timeZone.Name;
                record.City      = timeZone.City;
                record.GmtOffset = timeZone.GmtOffset;
                dbContext.SaveChanges();
                return(Ok(record));
            }

            return(BadRequest());
        }