public MemberViewModel GetNewMember(Guid appId, bool IsChild)
 {
     MemberViewModel mvm = new MemberViewModel
     {
         AppId = appId,
         IsChild = IsChild,
         IsRowInEditMode = true,
         IsNewRow = true,
         FirstName = "",
         MiddleInitial = "",
         LastName = ""
     };
     if (IsChild)
     {
         using (SlpContext context = new SlpContext())
         {
             mvm.ChildAttributes = context.ChildAttributeTypes.Where(a => a.Visible == true).Select(a => new NameValueViewModel { Name = a.Name, Value = a.Id }).OrderBy(a => a.Value).ToList();
         }
     }
     return mvm;
 }
        public List<MemberViewModel> MemberSave(MemberViewModel mvm)
        {
            TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;

            List<MemberViewModel> cvmList = new List<MemberViewModel>();
            using (SlpContext context = new SlpContext())
            {
                SlpApplication slpApp = context.SlpApplication.Find(mvm.AppId);
                if (slpApp == null)
                {
                    context.SlpApplication.Add(new SlpApplication { Id = mvm.AppId, CreateDate = DateTime.Now });
                }                

                if (mvm.Id == new Guid()) //add child
                {
                    mvm.Id = Guid.NewGuid();
                    context.Members.Add(new Member {
                        Id = mvm.Id,
                        SlpApplicationId = mvm.AppId,
                        FirstName = textInfo.ToTitleCase(mvm.FirstName.ToLower()),
                        LastName = textInfo.ToTitleCase(mvm.LastName.ToLower()),
                        MiddleInitial = mvm.MiddleInitial == "" || mvm.MiddleInitial == null ? "" : mvm.MiddleInitial.ToUpper(),
                        IsChild = mvm.IsChild,
                        CreatedDate = DateTime.Now });                    
                }
                else //update child
                {
                    Member child = context.Members.Where(a => a.Id == mvm.Id).FirstOrDefault();
                    child.FirstName = textInfo.ToTitleCase(mvm.FirstName.ToLower());                    
                    child.LastName = textInfo.ToTitleCase(mvm.LastName.ToLower());
                    child.MiddleInitial = mvm.MiddleInitial == "" || mvm.MiddleInitial == null ? "" : mvm.MiddleInitial.ToUpper();             
                }
                
                if (mvm.IsChild)
                {
                    context.MemberChildAttributes.RemoveRange(context.MemberChildAttributes.Where(a => a.MemberId == mvm.Id));
                    foreach (NameValueViewModel vm in mvm.ChildAttributes)
                    {
                        context.MemberChildAttributes.Add(new MemberChildAttribute { MemberId = mvm.Id, AttributeTypeId = vm.Value, IsSelected = vm.SelectedItem });
                    }
                }
                context.SaveChanges();
            }

            cvmList = GetMembers(mvm.AppId).Where(a => a.IsChild ==  mvm.IsChild).ToList();
            
            return cvmList;
        }
 public List<MemberViewModel> MemberDelete(MemberViewModel mvm)
 {
     List<MemberViewModel> cvmList = new List<MemberViewModel>();
     using (SlpContext context = new SlpContext())
     {
         Member member = context.Members.Find(mvm.Id);
         context.Members.Remove(member);
         context.SaveChanges();
     }
     cvmList = GetMembers(mvm.AppId).Where(a => a.IsChild == mvm.IsChild).ToList();
     return cvmList;
 }
예제 #4
0
 public JsonResult MemberDelete(MemberViewModel mvm)
 {
     List<MemberViewModel> cvmdb = appOrchestrator.MemberDelete(mvm);
     return Json(cvmdb, JsonRequestBehavior.AllowGet);
 }