public async Task<ActionResult> UpdateUserDescription(UserDetailsVM m)
        {
            // custom validator here ...

            m = await MembershipContext.UpdateUserDescription(User.Identity.GetUserId(), m);
            return View("UserDetails", m);
        }
 public async Task<ActionResult> UpdateUserProperties(UserDetailsVM m)
 {
     m = await MembershipContext.UpdateUserProperties(User.Identity.GetUserId(), m);
     return View("UserDetails", m);
 }
 public static async Task<UserDetailsVM> UpdateUserDescription(string id, UserDetailsVM model)
 {
     UserDetailServiceProxy udsvc = new UserDetailServiceProxy();
     var cntx = Cntx;
     var details = await udsvc.LoadEntityByKeyAsync(cntx, ApplicationContext.App.ID, id);
     if (details != null && !details.IsDescriptionLoaded)
     {
         details.Description = await udsvc.LoadEntityDescriptionAsync(cntx, ApplicationContext.App.ID, id);
         details.IsDescriptionLoaded = true;
     }
     bool changed = details.Description == null && model.Description != null || details.Description != null && model.Description == null ||
         details.Description != null && model.Description != null && details.Description.Trim() != model.Description.Trim();
     if (changed)
     {
         details.Description = model.Description;
         details.LastModified = DateTime.UtcNow;
         udsvc.AddOrUpdateEntities(Cntx, new UserDetailSet(), new UserDetail[] { details });
     }
     return await GetUserDetails(id, true);
 }
 public static async Task<UserDetailsVM> GetUserDetails(string id, bool direct = false)
 {
     UserDetailServiceProxy udsvc = new UserDetailServiceProxy();
     var cntx = Cntx;
     cntx.DirectDataAccess = direct;
     var details = await udsvc.LoadEntityByKeyAsync(cntx, ApplicationContext.App.ID, id);
     UserDetailsVM m = null;
     if (details != null)
     {
         if (!details.IsDescriptionLoaded)
         {
             details.Description = udsvc.LoadEntityDescription(cntx, ApplicationContext.App.ID, id);
             details.IsDescriptionLoaded = true;
         }
         m = new UserDetailsVM { Details = details };
         m.IsPhotoAvailable = !string.IsNullOrEmpty(details.PhotoMime);
     }
     else
     {
         m = new UserDetailsVM();
         m.IsPhotoAvailable = false;
     }
     UserDetailSet uds = new UserDetailSet();
     m.Genders = uds.GenderValues;
     QueryExpresion qexpr = new QueryExpresion();
     qexpr.OrderTks = new List<QToken>(new QToken[] { 
         new QToken { TkName = "ID" },
         new QToken { TkName = "asc" }
     });
     CommunicationTypeServiceProxy ctsvc = new CommunicationTypeServiceProxy();
     var lct = await ctsvc.QueryDatabaseAsync(Cntx, new CommunicationTypeSet(), qexpr);
     m.ChannelTypes = lct.ToArray();
     CommunicationServiceProxy csvc = new CommunicationServiceProxy();
     //qexpr = new QueryExpresion();
     //qexpr.OrderTks = new List<QToken>(new QToken[] { 
     //    new QToken { TkName = "TypeID" },
     //    new QToken { TkName = "asc" }
     //});
     //qexpr.FilterTks = new List<QToken>(new QToken[] { 
     //    new QToken { TkName = "UserID" },
     //    new QToken { TkName = "==" },
     //    new QToken { TkName = "\"" + id + "\"" },
     //    new QToken { TkName = "&&" },
     //    new QToken { TkName = "ApplicationID" },
     //    new QToken { TkName = "==" },
     //    new QToken { TkName = "\"" + ApplicationContext.App.ID + "\"" }
     //});
     //var lc = await csvc.QueryDatabaseAsync(Cntx, new CommunicationSet(), qexpr);
     var fkeys = new CommunicationSetConstraints
     {
         ApplicationIDWrap = new ForeignKeyData<string> { KeyValue = ApplicationContext.App.ID },
         TypeIDWrap = null, // no restriction on types
         UserIDWrap = new ForeignKeyData<string> { KeyValue = id }
     };
     var lc = await csvc.ConstraintQueryAsync(Cntx, new CommunicationSet(), fkeys, null);
     foreach (var c in lc)
     {
         c.Comment = await csvc.LoadEntityCommentAsync(Cntx, c.ID);
         c.IsCommentLoaded = true;
         c.CommunicationTypeRef = await csvc.MaterializeCommunicationTypeRefAsync(Cntx, c);
         m.Channels.Add(new { id = c.ID, label = c.DistinctString, addr = c.AddressInfo, comment = c.Comment, typeId = c.CommunicationTypeRef.TypeName });
     }
     return m;
 }
 public static async Task<UserDetailsVM> UpdateUserProperties(string id, UserDetailsVM model)
 {
     UserDetailServiceProxy udsvc = new UserDetailServiceProxy();
     var cntx = Cntx;
     var details = await udsvc.LoadEntityByKeyAsync(cntx, ApplicationContext.App.ID, id);
     int chgcnt = 0;
     if (details.Gender != model.Gender)
     {
         details.Gender = model.Gender;
         chgcnt++;
     }
     if (!details.BirthDate.HasValue && model.BirthDate.HasValue || details.BirthDate.HasValue && !model.BirthDate.HasValue ||
         details.BirthDate.HasValue && model.BirthDate.HasValue && details.BirthDate.Value != model.BirthDate.Value)
     {
         details.BirthDate = model.BirthDate;
         chgcnt++;
     }
     if (chgcnt > 0)
     {
         details.LastModified = DateTime.UtcNow;
         udsvc.AddOrUpdateEntities(Cntx, new UserDetailSet(), new UserDetail[] { details });
     }
     return await GetUserDetails(id, true);
 }