public async Task <ActionResult> Edit([Bind(Include = "id,title,desc,url,orders,flag")] item item, FormCollection collection) { try { var author = collection["author[]"]; var attach = collection["attach[]"]; item.author = "," + author + ","; item.attach = "," + attach + ","; db.items.Attach(item); var entry = db.Entry(item); entry.Property(m => m.title).IsModified = true; entry.Property(m => m.desc).IsModified = true; entry.Property(m => m.url).IsModified = true; entry.Property(m => m.flag).IsModified = true; entry.Property(m => m.orders).IsModified = true; entry.Property(m => m.author).IsModified = true; entry.Property(m => m.attach).IsModified = true; foreach (var gi in db.group_item.Where(m => m.item_id == item.id).ToList()) { db.group_item.Remove(gi); } foreach (var a in author.Split(',')) { group_item gi = new group_item(); gi.id = Guid.NewGuid(); gi.app_key = Common.Objects.groups.reportDay; gi.group_id = Guid.Parse(a); gi.item_id = item.id; gi.orders = 0; db.group_item.Add(gi); } item.updated_by = Authentication.Auth.AuthUser.id.ToString(); item.updated_at = DateTime.Now; await db.SaveChangesAsync(); this.success(TM.Common.Language.msgUpdateSucsess); return(RedirectToAction("Index")); } catch (Exception ex) { this.danger(TM.Common.Language.msgUpdateError); } ViewBag.department = await db.groups.Where(m => m.flag > 0 && m.app_key == Common.Objects.groups.department).OrderBy(m => m.title).ToListAsync(); ViewBag.groups = await db.groups.Where(m => m.flag > 0 && m.app_key == Common.Objects.groups.reportDay).ToListAsync(); return(View(item)); }
public async Task <ActionResult> Create([Bind(Include = "title,desc,url,orders,flag")] item item, FormCollection collection) { try { var author = collection["author[]"]; var attach = collection["attach[]"]; item.id = Guid.NewGuid(); item.app_key = Common.Objects.groups.reportDay; item.created_by = Authentication.Auth.AuthUser.id.ToString(); item.created_at = DateTime.Now; item.updated_by = Authentication.Auth.AuthUser.id.ToString(); item.updated_at = DateTime.Now; item.author = "," + author + ","; item.attach = "," + attach + ","; if (author != null) { foreach (var a in author.Split(',')) { group_item gi = new group_item(); gi.id = Guid.NewGuid(); gi.app_key = Common.Objects.groups.reportDay; gi.group_id = Guid.Parse(a); gi.item_id = item.id; gi.orders = 0; db.group_item.Add(gi); } } db.items.Add(item); await db.SaveChangesAsync(); this.success(TM.Common.Language.msgCreateSucsess); return(RedirectToAction("Create")); } catch (Exception) { this.danger(TM.Common.Language.msgCreateError); } ViewBag.department = await db.groups.Where(m => m.flag > 0 && m.app_key == Common.Objects.groups.department).OrderBy(m => m.title).ToListAsync(); ViewBag.groups = await db.groups.Where(m => m.flag > 0 && m.app_key == Common.Objects.groups.reportDay).ToListAsync(); return(View(item)); }
private void CollectGroupItemSystemData(group_item groupItem) { string groupName = groupItem.group.Value; IEnumerable <string> memberList = this.SearchGroupObjectsOnTarget(groupName); List <EntityItemStringType> cookedMemberList = new List <EntityItemStringType>(); if ((memberList == null) || (memberList.Count() == 0)) { cookedMemberList.Add(OvalHelper.CreateItemEntityWithStringValue("No Member")); cookedMemberList[0].status = StatusEnumeration.doesnotexist; } else { foreach (string memberName in memberList) { cookedMemberList.Add(OvalHelper.CreateItemEntityWithStringValue(memberName)); } } groupItem.user = cookedMemberList.ToArray(); }