public ActionResult Create() { ViewBag.ReturnUrl = Request.UrlReferrer == null ? "/Code" : Request.UrlReferrer.AbsoluteUri; EditGroupBindingModel model = new EditGroupBindingModel(); model.Code = Guid.NewGuid().ToString().GetHashCode().ToString("x"); return(View(model)); }
public ActionResult Edit([Bind(Include = "Id, Name, Sport, Country, Town, Address")] EditGroupBindingModel bindingModel) { if (ModelState.IsValid) { this._service.EditGroup(bindingModel); return(RedirectToAction("Index")); } return(View(bindingModel)); }
public async Task <ActionResult> Create( [Bind(Include = "Name,Description,Code,Picture")] EditGroupBindingModel model) { if (ModelState.IsValid) { var group = RepositoryProvider.Get <GroupRepository>() .FirstOrDefault( p => p.Name.ToUpper() == model.Name.ToUpper() || p.Code.ToUpper() == model.Code.ToUpper()); if (group != null) { ModelState.AddModelError("", "Name or Code has been used."); ViewBag.ReturnUrl = string.IsNullOrEmpty(Request.QueryString["returnUrl"]) ? "/Code" : HttpUtility.UrlDecode(Request.QueryString["returnUrl"]); } else { group = new Group() { GroupId = Guid.NewGuid(), Name = model.Name, Description = model.Description, Code = model.Code, CreateDate = DateTime.UtcNow, CreatorId = CurrentAccess.UserId }; if (model.Picture != null && model.Picture.ContentLength > 0) { var stream = new MemoryStream(); ImageHelper.Resize(model.Picture.InputStream, stream, 300, ImageFormat.Jpeg); var azureStorageHelper = new AzureStorageHelper(ConfigHelper.AzureStorageConnectionString); var newPicture = await azureStorageHelper.SaveFileStream(stream, Guid.NewGuid() + ".jpg", AzureStorageHelper.FileUsage.UserPhotos); group.Picture = newPicture; } RepositoryProvider.Get <GroupRepository>().Insert(group); RepositoryProvider.Save(); return (Redirect(string.IsNullOrEmpty(Request.QueryString["returnUrl"]) ? "/Code" : HttpUtility.UrlDecode(Request.QueryString["returnUrl"]))); } } return(View(model)); }
public void EditGroup(EditGroupBindingModel bindingModel) { var group = Context.Groups.Find(bindingModel.Id); if (group != null) { group.Name = bindingModel.Name; group.Sport = bindingModel.Sport; group.Location.Country = bindingModel.Country; group.Location.Town = bindingModel.Town; group.Location.Address = bindingModel.Address; } Context.SaveChanges(); }
public ActionResult Edit(EditGroupBindingModel model) { var group = this.Data.Group.Find(model.Id); if (group == null) { return(HttpNotFound()); } group.Name = model.Name; group.Description = model.Description; Data.Group.Update(group); Data.SaveChanges(); return(RedirectToAction("Get", new { groupId = model.Id, p = 1 })); }
public async Task <IHttpActionResult> EditGroup(string id, EditGroupBindingModel model) { var userId = this.User.Identity.GetUserId(); if (userId == null) { return(this.BadRequest("Invalid session token.")); } if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } if (model == null) { return(this.BadRequest("Invalid input data")); } var groupForCurrentUser = await this.Data.Groups.All() .Where(g => g.Users.Any(u => u.Id == userId) && g.Id == new Guid(id)) .ToListAsync(); var groupResult = groupForCurrentUser.FirstOrDefault(); if (groupResult == null) { return(this.BadRequest("Group id is not correct or you are not allowed to edit it.")); } groupResult.Description = model.Description ?? groupResult.Description; groupResult.Name = model.Name ?? groupResult.Name; await this.Data.SaveChangesAsync(); return(this.StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult EditGroupById([FromUri] int groupId, [FromBody] EditGroupBindingModel model) { var group = this.Data.Groups.Find(groupId); if (group == null) { return(this.NotFound()); } if (!ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } var currentUserId = User.Identity.GetUserId(); var currentUser = this.Data.Users.FirstOrDefault(x => x.Id == currentUserId); if (currentUser == null) { return(this.BadRequest("Invalid user token! Please login again!")); } if (currentUser != group.Owner) { return(this.BadRequest("Not allowed. User must be owner of group.")); } group.Name = model.Name; group.Description = model.Description; group.WallPicture = model.WallPicture; this.Data.SaveChanges(); var dbGroup = this.Data.Groups.Find(group.Id); return(this.Ok(CreateGroupViewModel.CreateGroupPreview(currentUser, dbGroup))); }
public ActionResult Edit(string id) { ViewBag.ReturnUrl = Request.UrlReferrer == null ? "/Code" : Request.UrlReferrer.AbsoluteUri; if (string.IsNullOrEmpty(id)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var group = RepositoryProvider.Get <GroupRepository>().GetById(Guid.Parse(id)); if (group == null) { return(HttpNotFound()); } var editGroup = new EditGroupBindingModel() { GroupId = group.GroupId, Name = group.Name, Description = group.Description, Code = group.Code, PictureUrl = group.Picture }; return(View(editGroup)); }