public IHttpActionResult Post([FromUri] string id, [FromBody] Entities.Storytime storytime) { var db = new PetaPoco.Database("AGSoftware"); storytime.DateCreated = System.DateTime.Now; storytime.UserId = Storytime.Providers.UserHelper.GetUserId(this.User.Identity.Name); storytime.UsersNotified = false; db.Insert(storytime); if (storytime.StorytimeType == StorytimeType.Group) { StorytimeGroup storytimegroup = new StorytimeGroup(); storytimegroup.StorytimeId = storytime.StorytimeId; storytimegroup.UserGroupId = storytime.UserGroupId; storytimegroup.UsersNotified = false; db.Insert(storytimegroup); return(Ok(storytime.StorytimeId)); } else if (storytime.StorytimeType == StorytimeType.User) { StorytimeUserList storytimeuserlist = new StorytimeUserList(); foreach (AspNetUsers user in storytime.Users) { storytimeuserlist.StorytimeId = storytime.StorytimeId; storytimeuserlist.UserId = user.Id; storytimeuserlist.UserNotified = false; db.Insert(storytimeuserlist); } storytimeuserlist.StorytimeId = storytime.StorytimeId; storytimeuserlist.UserId = storytime.UserId; storytimeuserlist.UserNotified = false; db.Insert(storytimeuserlist); return(Ok(storytime.StorytimeId)); } else { return(BadRequest("StorytimeType is invalid")); } }
public IHttpActionResult Post([FromUri] string id, [FromBody]Entities.Storytime storytime) { var db = new PetaPoco.Database("AGSoftware"); storytime.DateCreated = System.DateTime.Now; storytime.UserId = Storytime.Providers.UserHelper.GetUserId(this.User.Identity.Name); storytime.UsersNotified = false; db.Insert(storytime); if (storytime.StorytimeType == StorytimeType.Group) { StorytimeGroup storytimegroup = new StorytimeGroup(); storytimegroup.StorytimeId = storytime.StorytimeId; storytimegroup.UserGroupId = storytime.UserGroupId; storytimegroup.UsersNotified = false; db.Insert(storytimegroup); return Ok(storytime.StorytimeId); } else if (storytime.StorytimeType == StorytimeType.User) { StorytimeUserList storytimeuserlist = new StorytimeUserList(); foreach (AspNetUsers user in storytime.Users) { storytimeuserlist.StorytimeId = storytime.StorytimeId; storytimeuserlist.UserId = user.Id; storytimeuserlist.UserNotified = false; db.Insert(storytimeuserlist); } storytimeuserlist.StorytimeId = storytime.StorytimeId; storytimeuserlist.UserId = storytime.UserId; storytimeuserlist.UserNotified = false; db.Insert(storytimeuserlist); return Ok(storytime.StorytimeId); } else return BadRequest("StorytimeType is invalid"); }