public TeamMember(Team item) { this.Id = item.UserID; this.DisplayName = item.UserAccount.GetDisplayName(); this.RoleId = item.RoleID; this.RoleName = item.Role.RoleName; }
// POST api/teammanage public HttpResponseMessage Post(TeamMemberModel value) { using (var ctx = new Entities()) { Team t = ctx.Teams.FirstOrDefault(i => i.CellID == value.CellId && i.UserID == value.UserId); bool createdNew = false; if (t != null) { t.RoleID = value.RoleId; } else { t = new Team() { CellID = value.CellId, UserID = value.UserId, RoleID = value.RoleId }; ctx.Teams.Add(t); createdNew = true; } if (ctx.SaveChanges() != 0) { if(createdNew) { return new HttpResponseMessage(HttpStatusCode.Created); } else { return new HttpResponseMessage(HttpStatusCode.OK); } } else { return new HttpResponseMessage(HttpStatusCode.InternalServerError); } } }