public ActionResult Edit([Bind(Include = "id,id_key,title,level,desc,orders,extras,flag")] Models.group group_tmp) { if (ModelState.IsValid) { var group = db.groups.Find(group_tmp.id); group.id_key = group_tmp.id_key; group.title = group_tmp.title; group.level = group_tmp.level; group.desc = group_tmp.desc; group.orders = group_tmp.orders; group.extras = group_tmp.extras; group.flag = group_tmp.flag; group.updated_by = Authentication.Auth.AuthUser.id.ToString(); group.updated_at = DateTime.Now; db.Entry(group).State = EntityState.Modified; db.SaveChanges(); this.success(TM.Common.Language.msgUpdateSucsess); return(RedirectToAction("Index")); } else { this.danger(TM.Common.Language.msgUpdateError); } return(View(group_tmp)); }
// GET: Department/Details/5 public ActionResult Details(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Models.group group = db.groups.Find(id); if (group == null) { return(HttpNotFound()); } return(View(group)); }
public ActionResult Create(group group) { var _user = GetLoggedUser(); if (_user == null) { return RedirectToAction("LogOn", "Account"); } if (ModelState.IsValid) { using (TransactionScope scope = new TransactionScope()) { collection coll = new collection { collection_name = group.collection.collection_name, created_by = _user.id, created_date = DateTime.Now }; db.collections.Add(coll); db.SaveChanges(); group newgroup = new Models.group { collection = coll, description = group.description }; db.groups.Add(newgroup); db.SaveChanges(); //add the user who created the group as one of the group member group_members gm = new group_members { group = newgroup, user_id = _user.id }; db.group_members.Add(gm); db.SaveChanges(); scope.Complete(); } return RedirectToAction("Index"); } ModelState.AddModelError("", "Could not create new group"); return View(group); }
public ActionResult Create([Bind(Include = "id_key,title,level,desc,orders,extras,flag")] Models.group group) { if (ModelState.IsValid) { group.id = Guid.NewGuid(); group.app_key = Common.Objects.groups.department; group.created_by = Authentication.Auth.AuthUser.id.ToString(); group.created_at = DateTime.Now; db.groups.Add(group); db.SaveChanges(); this.success(TM.Common.Language.msgCreateSucsess); return(RedirectToAction("Create")); } else { this.danger(TM.Common.Language.msgCreateError); } return(View(group)); }
public IHttpActionResult CreateGroup(MednaNetAPIClient.Models.Groups group) { var APIReturn = new Models.APIReturn(); IEnumerable <string> headerValues = Request.Headers.GetValues("Authorization"); string installKey = headerValues.FirstOrDefault(); if (installKey == "") { return(ResponseMessage(Models.Errors.InstallKeyBlank(Request))); } try { Models.Installs.checkinInstall(installKey); } catch (Exception ex) { return(ResponseMessage(Models.Errors.InstallCheckinFailed(Request))); } try { using (Models.MedLaunchChatEntities db = new Models.MedLaunchChatEntities()) { var install = (from q in db.installs where q.code == installKey select q).FirstOrDefault(); if (install != null) { Models.group newGroup = new Models.group(); newGroup.group_description = group.groupDescription; newGroup.group_name = group.groupName; newGroup.group_owner = install.id; if (newGroup.group_name.Length > 20) { newGroup.group_name = newGroup.group_name.Substring(0, 19); } db.groups.Add(newGroup); try { db.SaveChanges(); APIReturn.returnMessage = "Group created."; } catch (Exception e) { APIReturn.returnMessage = "Could not create group."; return(new System.Web.Http.Results.ExceptionResult(e, this)); } Models.group_members groupMember = new Models.group_members(); groupMember.awaiting_invite_confrim = false; groupMember.group_id = newGroup.id; groupMember.install_id = install.id; db.group_members.Add(groupMember); try { db.SaveChanges(); APIReturn.returnMessage += "| Install added to group"; } catch (Exception e) { APIReturn.returnMessage = "Could not add install to group."; return(new System.Web.Http.Results.ExceptionResult(e, this)); } } else { APIReturn.returnMessage = "Install not found"; } } } catch (Exception ex) { HttpError err = new HttpError("Error creating group. "); return(ResponseMessage(Request.CreateResponse(HttpStatusCode.InternalServerError, err))); } return(Ok()); }