public GroupMember MakeGroupMembers(GroupMember gm) { try { using (shoponlineDataContext context = DbUtils.Create()) { context.GroupMembers.InsertOnSubmit(gm); context.SubmitChanges(); return gm; } } catch (Exception) { } return null; }
public ActionResult AddGroup(string txtGroupName, string txtDescription, string radType, string hidGroupId) { try { ViewData["txtGroupName"] = txtGroupName; ViewData["txtDescription"] = txtDescription; ViewData["radType"] = radType; Boolean validInput = true; if (string.IsNullOrWhiteSpace(txtGroupName)) { validInput = false; ViewData[Constants.OPERATIONALMESSAGE] = Utils.getErrorMessage("Input field required", "Please enter Group Name"); } if (string.IsNullOrWhiteSpace(txtDescription)) { validInput = false; ViewData[Constants.OPERATIONALMESSAGE] = Utils.getErrorMessage("Input field required", "Please enter Description of the Group"); } if (string.IsNullOrWhiteSpace(radType)) { validInput = false; ViewData[Constants.OPERATIONALMESSAGE] = Utils.getErrorMessage("Input field required", "Please select Group Type"); } if (validInput == true) { Group g = new Group(); Group updateGroup = new Group(); g.Name = txtGroupName; g.GroupDescription = txtDescription; g.GroupType = radType; if (!string.IsNullOrWhiteSpace(hidGroupId)) { g.GroupId = Convert.ToInt64(new SecurityManager().DecodeString(hidGroupId)); } if (g.GroupId > 0) { new Group().UpdateGroup(g); return RedirectToRoute(new RouteValueDictionary(new { controller = "Groups", action = "ManageGroups", RecUpdateOperation = "1" })); } else { g.User_Id = new ShopOnline.Filters.UserSession().getUserSession().UserId; g.CreatedOn = DateTime.UtcNow; Group group = g.AddGroup(g); GroupMember gm = new GroupMember(); gm.Group_Id = group.GroupId; gm.User_Id = new ShopOnline.Filters.UserSession().getUserSession().UserId; gm.MemberRole = Convert.ToInt32(GroupMemberRolesType.GroupAdmin); gm.CreatedOn = DateTime.UtcNow; gm.AddBy = new ShopOnline.Filters.UserSession().getUserSession().UserId; gm = gm.MakeGroupMembers(gm); if (group != null && gm!=null) { return RedirectToRoute(new RouteValueDictionary(new { controller = "Groups", action = "ManageGroups", RecCreateOperation = "1" })); } else { ViewData[Constants.OPERATIONALMESSAGE] = Utils.getErrorMessage("Input field required", "Sorry record could not be saved"); } } } } catch (Exception ex) { } return View(); }