// DELETE api/teammanage/5 public HttpResponseMessage Delete(TeamMemberModel value) { using (var ctx = new Entities()) { Team t = ctx.Teams.FirstOrDefault(i => i.CellID == value.CellId && i.UserID == value.UserId); if (t != null) { ctx.Teams.Remove(t); if (ctx.SaveChanges() != 0) { return new HttpResponseMessage(HttpStatusCode.OK); } else { return new HttpResponseMessage(HttpStatusCode.InternalServerError); } } else { return new HttpResponseMessage(HttpStatusCode.NotFound); } } }
// POST api/login public HttpResponseMessage Post(EmailModel value) { try { using (var ctx = new Entities()) { UserAccount user = ctx.UserAccounts.FirstOrDefault(i => i.Email == value.Email); if (user != null && user.Enabled) { try { Mail.SendNewPasswordTokenMail(user); return new HttpResponseMessage(HttpStatusCode.Accepted); } catch (Exception) { return new HttpResponseMessage(HttpStatusCode.RequestTimeout); } } else { return new HttpResponseMessage(HttpStatusCode.NotFound); } } } catch { return new HttpResponseMessage(HttpStatusCode.InternalServerError); } }
/// <summary> /// Validates user login. /// </summary> /// <param name="model"></param> /// <returns></returns> public static AuthResponse Login(AuthenticationModel model) { using (var ctx = new Entities()) { /* Find user by email address. */ UserAccount user = ctx.UserAccounts.Where(i => i.Email == model.Email).FirstOrDefault(); /* Validate user password if it exists. */ if (user != null) { if (ValidatePassword(user, model.Password)) { if (true == user.Enabled) { /* Sets authentication ticket. */ var ticket = MakeAuthCookie(user, model.RememberMe); HttpCookie ck = new HttpCookie(FormsAuthentication.FormsCookieName, ticket); HttpContext.Current.Response.Cookies.Set(ck); return AuthResponse.Ok; } else { return AuthResponse.AccountNotEnabled; } } } } return AuthResponse.InvalidCredentials; }
// POST api/register public HttpResponseMessage Post(AuthenticationModel value) { try { using (var ctx = new Entities()) { UserAccount ua = ctx.UserAccounts.Where(i => i.Email == value.Email).FirstOrDefault(); /* Check if user isn't registered yet. */ if (ua == null) { /* Create the new user and salt the password. */ ua = new UserAccount() { Email = value.Email, RegisterDate = DateTime.Now }; ua.Password = Authentication.MakePassword(ua, value.Password); ctx.UserAccounts.Add(ua); /* Save changes. */ if (ctx.SaveChanges() != 0) { Mail.SendRegisterTokenMail(ua); return new HttpResponseMessage(HttpStatusCode.Created); } else { return new HttpResponseMessage(HttpStatusCode.InternalServerError); } } return new HttpResponseMessage(HttpStatusCode.Conflict); } } catch { return new HttpResponseMessage(HttpStatusCode.InternalServerError); } }
/// <summary> /// Get cell ID from its tag. /// </summary> /// <param name="cell"></param> /// <returns></returns> public static Cell GetCell(this object cell) { using (var ctx = new Entities()) { return ctx.GetCell(cell); } }
// POST api/profile public HttpResponseMessage Post(MyProfileModel value) { try { using (var ctx = new Entities()) { /* Get logged user ID. That won't be fetched from the form to avoid XSS atacks. */ int userid = Authentication.GetLoggedUser().UserID; UserProfile profile = ctx.UserProfiles.FirstOrDefault(i => i.UserID == userid); /* If there isn't a profile for this user yet, create it. */ if (profile == null) { profile = ctx.UserProfiles.Add(new UserProfile() { UserID = userid }); } /* Set user profile info. */ profile.FullName = value.FullName; profile.BirthDate = value.BirthDate; profile.UserTheme = value.UserTheme; profile.Location = value.Location; profile.Biography = value.Biography; /* Save changes and refresh user's full name in the cookie. */ ctx.SaveChanges(); Authentication.RefreshCookie(); return new HttpResponseMessage(HttpStatusCode.OK); } } catch { return new HttpResponseMessage(HttpStatusCode.InternalServerError); } }
public ActionResult Create(BaselineCreateModel model) { if (model.Descricao == null || model.Descricao.Trim().Length == 0) { Error("Digite a descrição do baseline!"); } else { using (var ctx = new Entities()) { Baseline bl = new Baseline(); bl.CellID = RouteData.Values["cell"].GetCellID(); bl.UserID = Authentication.GetLoggedUser().UserID; bl.SetDate = DateTime.Parse(model.SetDate); bl.Message = model.Descricao; ctx.Baselines.Add(bl); if (ctx.SaveChanges() != 0) { Success("Baseline registrado com sucesso!"); return RedirectToAction("Index"); } else { Error("Erro ao tentar registrar o baseline!"); } } } return View(model); }
public static List<Cell> GetCellTags() { using (var ctx = new Entities()) { var list = (from i in ctx.Cells orderby i.CellName ascending select i).ToList(); return list; } }
public RequirementsIndexModel(GetRequirementsIndex_Result item) { this.Id = item.Tag; this.UserName = new UserNameModel(item.UserID); this.Modified = item.RevisionDate; this.Summary = item.Title; using (var ctx = new Entities()) { int logged = Authentication.GetLoggedUser().UserID; this.Published = item.Published; this.Rated = (ctx.RequirementRatings.FirstOrDefault(i => i.RevisionID == item.RevisionID) != null); this.Approved = (ctx.RequirementRatings.FirstOrDefault(i => i.RevisionID == item.RevisionID && i.Approved == true) != null); this.Archived = (ctx.RequirementRevisions.FirstOrDefault(i => i.RevisionID == item.RevisionID && i.Archived == true) != null); var bl = (from i in ctx.Baselines orderby i.SetDate descending select i.SetDate).Take(1); if (bl != null && bl.Count() == 1) { this.LatestBaseline = bl.ToArray()[0]; } } if (item.BaselineDate.HasValue) { this.Status = "Implementado"; if (this.LatestBaseline.HasValue && this.LatestBaseline.Value >= item.BaselineDate.Value) { this.Status = "Baseline"; } else { this.Status = "Implementado"; } } else if (this.Published == false) { this.Status = "Em edição"; } else if (this.Rated == false) { this.Status = "Ag. avaliação"; } else if (this.Approved == false) { this.Status = "Reprovado"; this.Published = false; } else if (this.Archived) { this.Status = "Cancelado"; } else { this.Status = "Aprovado"; } }
public ActionResult Details(string tag) { using (var ctx = new Entities()) { RequirementsDetailsModel model = new RequirementsDetailsModel(ctx.GetRequirementDetails(tag, null).FirstOrDefault()); RouteData.Values["title"] = model.Summary; return View(model); } }
public static bool IsLoggedUserManager() { AuthCookieModel user = GetLoggedUser(); using (var ctx = new Entities()) { var ret = from t in ctx.Teams where t.UserID == user.UserID && t.Role.RoleName.ToLower().Contains("dono") select t; return (ret.Count() != 0); } }
public ActionResult Details(string tag) { using (var ctx = new Entities()) { RequirementsDetailsModel req = new RequirementsDetailsModel(ctx.GetRequirementDetails(tag, null).FirstOrDefault()); RouteData.Values["title"] = req.Summary; return View("Rate", new RateTopicModel(req)); } }
public ActionResult View(long tag) { using (var ctx = new Entities()) { var item = ctx.GetBaselineRequirementDetails(tag).FirstOrDefault(); var model = new BaselineRequirementDetailsModel(item); return View(model); } }
public ActionResult Edit(string tag) { using (var ctx = new Entities()) { StoriesCreateModel model = new StoriesCreateModel(ctx.GetRequirementDetails(tag, null).FirstOrDefault()); RouteData.Values["title"] = model.Summary; return View("Create", model); } }
public ActionResult Details(UserRatingModel model) { using (var ctx = new Entities()) { ctx.SubmitRating(model.Id, Authentication.GetLoggedUser().UserID, model.Approved, model.Comments); Success("Obrigado por avaliar este tópico!"); return RedirectToRoute("Cells", new { @action = "Index" }); } }
public static TeamManageModel GetTeam(int cellId) { using (var ctx = new Entities()) { var item = ctx.Cells.FirstOrDefault(i => i.CellID == cellId); var model = new TeamManageModel(item); return model; } }
public static List<TeamIndexModel> GetTeams() { using (var ctx = new Entities()) { var list = (from i in ctx.Cells orderby i.CellName ascending select i).ToList(); var model = new List<TeamIndexModel>(); list.ForEach(i => model.Add(new TeamIndexModel(i))); return model; } }
public static List<RoleModel> GetRoles() { using (var ctx = new Entities()) { var list = (from i in ctx.Roles orderby i.RoleName ascending select i).ToList(); var ret = new List<RoleModel>(); list.ForEach(i => ret.Add(new RoleModel(i))); return ret; } }
public RequirementCreateModel(RequirementCreateModel item) { using (var ctx = new Entities()) { this.StoryId = item.StoryId; this.Summary = item.Summary; this.Text = item.Text; this.Message = item.Message; } }
public StoriesDetailsModel(GetRequirementDetails_Result item) { this.Id = item.Tag; this.RevisionId = item.RevisionID; this.UserName = new UserNameModel(item.UserID); this.RevisionNumber = item.RevisionNumber; this.RevisionDate = item.RevisionDate; this.Summary = item.Title; this.Text = item.Text; this.Published = item.Published; using (var ctx = new Entities()) { int logged = Authentication.GetLoggedUser().UserID; this.Rated = (ctx.RequirementRatings.FirstOrDefault(i => i.RevisionID == item.RevisionID) != null); this.Approved = (ctx.RequirementRatings.FirstOrDefault(i => i.RevisionID == item.RevisionID && i.Approved == true) != null); if (this.Rated) { this.ComentarioRevisao = (ctx.UserRatings.FirstOrDefault(i => i.RevisionID == item.RevisionID).Comments); } } if(item.BaselineDate.HasValue) { this.Published = this.Rated = this.Implemented = true; this.Status = "Atendida"; } else if (this.Published == false) { this.Status = "Em edição"; } else if (this.Rated == false) { this.Status = "Publicada, aguardando avaliação"; } else if (this.Approved == false) { this.Status = "Reprovado"; if (this.ComentarioRevisao != null && this.ComentarioRevisao.Length != 0) { this.Status += " - Comentários: " + this.ComentarioRevisao; } this.Published = false; } else { this.Status = "Aprovada, aguardando documentação"; } }
public static List<TeamUser> GetTeamUsers() { List<TeamUser> ret = new List<TeamUser>(); using (var ctx = new Entities()) { var list = ctx.UserAccounts.ToList(); list.ForEach(i => ret.Add(new TeamUser(i))); } ret.Sort(); return ret; }
public ActionResult Create() { List<BaselineRequirementsModel> reqs = new List<BaselineRequirementsModel>(); using (var ctx = new Entities()) { int cellID = RouteData.Values["cell"].GetCellID(); List<GetRequirementsForBaseline_Result> list = ctx.GetRequirementsForBaseline(cellID).ToList(); list.ForEach(i => reqs.Add(new BaselineRequirementsModel(i))); } var model = new BaselineCreateModel(reqs); return View(model); }
public static List<BaselineIndexModel> GetModels(object cell) { List<BaselineIndexModel> ret = new List<BaselineIndexModel>(); using (var ctx = new Entities()) { int parent = ctx.GetCellID(cell); var list = ctx.GetBaselineList(parent).ToList(); list.ForEach(i => ret.Add(new BaselineIndexModel(i))); } return ret; }
public static List<TeamMember>GetTeamMembers(int cellId) { List<TeamMember> ret = new List<TeamMember>(); using (var ctx = new Entities()) { var list = ctx.Teams.Where(i => i.CellID == cellId).ToList(); list.ForEach(i => ret.Add(new TeamMember(i))); } ret.Sort(); return ret; }
// POST api/login public HttpResponseMessage Post(RequirementNameModel model) { try { using (var ctx = new Entities()) { ctx.ArchiveRequirement(model.CellID, model.Tag); ctx.SaveChanges(); return new HttpResponseMessage(HttpStatusCode.OK); } } catch { return new HttpResponseMessage(HttpStatusCode.InternalServerError); } }
public ActionResult MyProfile() { using (var ctx = new Entities()) { int userid = Authentication.GetLoggedUser().UserID; UserProfile up = ctx.UserProfiles.FirstOrDefault(i => i.UserID == userid); if (up == null) { up = new UserProfile(); } var profile = new MyProfileModel(up); ViewBag.UserThemeList = new Choice(Utils.GetThemes(), true, up.UserTheme).GetSelectList(); return View(profile); } }
// POST api/profile public HttpResponseMessage Post(UseExistingRequirementModel value) { try { using (var ctx = new Entities()) { int userID = Authentication.GetLoggedUser().UserID; ctx.SelectRequirement(value.Cell, value.LeftTag, value.RightTag, userID, "Alteração de requisito para atender uma nova história"); ctx.SaveChanges(); return new HttpResponseMessage(HttpStatusCode.OK); } } catch { return new HttpResponseMessage(HttpStatusCode.InternalServerError); } }
public BaselineDetailsModel(int id) { using (var ctx = new Entities()) { var bl = ctx.Baselines.FirstOrDefault(i => i.BaselineID == id); if (bl != null) { this.Id = bl.BaselineID; this.Descricao = bl.Message; this.SetDate = bl.SetDate; var list = ctx.GetBaselineRequirements(bl.BaselineID).ToList(); this.Requisitos = new List<BaselineRequirementsModel>(); list.ForEach(i => this.Requisitos.Add(new BaselineRequirementsModel(i))); } } }
public ActionResult Edit(int id) { using (var ctx = new Entities()) { var item = ctx.Roles.FirstOrDefault(i => i.RoleID == id); if (item != null) { var model = new RoleModel(item); RouteData.Values["title"] = model.RoleName; return View("Create", model); } else { Error("Papel inválido!"); return RedirectToAction("Index"); } } }
public ActionResult Manage(int id) { using (var ctx = new Entities()) { var model = TeamManageModel.GetTeam(id); var mb = (from m in ctx.UserAccounts orderby m.UserID select m).ToList(); Dictionary<int, string> members = new Dictionary<int, string>(); mb.ForEach(i => members.Add(i.UserID, i.GetDisplayName())); ViewBag.MembersList = new Choice(members).GetSelectList(); var rl = (from r in ctx.Roles orderby r.RoleName select r).ToList(); Dictionary<int, string> roles = new Dictionary<int, string>(); rl.ForEach(i => roles.Add(i.RoleID, i.RoleName)); ViewBag.RolesList = new Choice(roles).GetSelectList(); return View(model); } }