Пример #1
0
        /// <summary>
        /// Update a single member’s information. Update the information for an existing member (even if they are marked as deleted). Note that this method allows the email address to be updated (which cannot be done with a POST, since in that case the email address is used to identify the member).
        /// </summary>
        /// <param name="memberId">Member identifier.</param>
        /// <param name="member">Class representing fields to update member information.</param>
        /// <returns>True if the member was updated successfully</returns>
        /// <remarks>Http404 if no member is found.</remarks>
        public bool UpdateSingleMemberInformation(string memberId, UpdateMember member)
        {
            var request = new RestRequest(Method.PUT);
            request.Resource = "/{accountId}/members/{memberId}";
            request.AddUrlSegment("memberId", memberId);

            request.RequestFormat = DataFormat.Json;
            request.JsonSerializer = new EmmaJsonSerializer();
            request.AddBody(member);

            return Execute<bool>(request);
        }
Пример #2
0
 public Form2(ClientTopicsManager client, String pseudo, String password)
 {
     transm.AddReceiveDel(receiveMessage);
     this.client   = client;
     this.pseudo   = pseudo;
     this.password = password;
     this.topic    = "";
     this.Text     = pseudo;
     InitializeComponent();
     textChat   += new UpdateChat(this.showText);
     textTopic  += new UpdateTopic(this.showTopic);
     textMember += new UpdateMember(this.showMember);
     showTopic();
 }
Пример #3
0
        public UpdateMember GetMemberInfo(string MemberId)
        {
            var         member = new Member();
            GetUserPara para   = new GetUserPara()
            {
                MemberId = MemberId
            };

            string returnStr = ShareService.Instance.SendApi("Member/GetMemberInfo", JsonConvert.SerializeObject(para));

            member = JsonConvert.DeserializeObject <Member>(returnStr);
            UpdateMember updatemodel = new UpdateMember();

            updatemodel.OriginArea = member.Area;
            member.Area            = null; //放null multiselect才可以繫結 否則頁面會抓不到資料
            updatemodel.User       = member;

            return(updatemodel);
        }
Пример #4
0
        public Result UpdateMember(UpdateMemberViewModel model)
        {
            var result = new Result();

            string Msg   = string.Empty;
            bool   check = true;
            Member User  = model.UpdateModel.User;

            if (!ShareService.Instance.CheckFormat(User.Phone, @"^[\d]*$", 10, ref Msg))
            {
                result.Message += $"手機{Msg}\r";
                check           = false;
            }
            if (check == false)
            {
                result.ReturnNo = -1;
                return(result);
            }
            User.Address = $"{model.addressCity}|{model.addressArea}|{User.Address}";
            //處理圖片
            if (model.Image != null && model.Image.ContentLength > 0)
            {
                //存到資料夾
                var FileName = User.MemberId + DateTime.Now.ToString("yyyyMMdd");
                var FilePath = Path.Combine(HttpContext.Current.Server.MapPath("~/MemberImage/"), FileName);
                model.Image.SaveAs(FilePath);
                User.Image = FileName;//存圖片檔名
            }
            //開始更新
            var input = new UpdateMember()
            {
                User       = User,
                OriginArea = model.UpdateModel.OriginArea
            };

            string returnStr = ShareService.Instance.SendApi("Member/UpdateMember", JsonConvert.SerializeObject(input));

            result = JsonConvert.DeserializeObject <Result>(returnStr);

            return(result);
        }
        public ActionResult UpdateMember()
        {
            UpdateService         service = new UpdateService();
            UpdateMemberViewModel model   = new UpdateMemberViewModel();

            //檢查是否登入狀態
            if (LoginState)
            {
                string City     = string.Empty;
                string Area     = string.Empty;
                string Address  = string.Empty;
                User   user     = GetMemberInfo();
                string MemberId = user.MemberId;

                UpdateMember updatemodel  = service.GetMemberInfo(MemberId);
                string[]     AddressArray = updatemodel.User.Address.Split('|');
                if (AddressArray.Length == 3)
                {
                    City = AddressArray[0];
                    Area = AddressArray[1];
                    updatemodel.User.Address = AddressArray[2];
                }


                model.addressCity     = City;
                model.addressArea     = Area;
                model.addressCityList = new SelectList(service.GetCity(City), "Value", "Text");
                model.addresAreaList  = new SelectList(service.GetArea(), "Value", "Text", Area);
                model.AreaList        = new MultiSelectList(service.GetCity(updatemodel.OriginArea.ToArray()), "Value", "Text", updatemodel.OriginArea);
                model.UpdateModel     = updatemodel;
            }
            else
            {
                return(RedirectToAction("Login", "Home"));
            }


            return(View(model));
        }
Пример #6
0
        public Result Update(UpdateMember model)
        {
            var result = new Result();

            try
            {
                result = strategy.Update(model.User);
                if (result.ReturnNo == 1)
                {
                    //相互取差集 要新增或刪掉的部分
                    List <string> insert = model.User.Area.Except(model.OriginArea).ToList();
                    List <string> delete = model.OriginArea.Except(model.User.Area).ToList();

                    foreach (var area in insert)
                    {
                        result = strategy.InsertUserArea(model.User.MemberId, area);
                    }
                    foreach (var area in delete)
                    {
                        result = strategy.DeleteUserArea(model.User.MemberId, area);
                    }
                }
                //更新照片
                if (!string.IsNullOrEmpty(model.User.Image))
                {
                    result = UpdateUserPhoto(model.User.MemberId, model.User.Image);
                }
            }
            catch (Exception ex)
            {
                LogService.LogTxt("更新資料例外錯誤" + ex.ToString());
                result.ReturnNo = -99;
                result.Message  = "更新資料例外錯誤";
            }


            return(result);
        }
Пример #7
0
        public ResponseMessage Put(int id, [FromBody] UpdateMember updateMember)
        {
            if (updateMember != null & ModelState.IsValid)
            {
                var data = memberSevices.GetById(id);
                if (data == null)
                {
                    responseMessage.Error();
                }
                else
                {
                    data.Description = updateMember.Description;
                    data.Name        = updateMember.Name;
                    memberSevices.Update(data);
                }
            }
            else
            {
                responseMessage.Error();
            }

            return(responseMessage);
        }
Пример #8
0
        /// <summary>
        /// Updates a detached graph of entities by performing a diff comparison of object keys.
        /// Author: Brent McKendrick
        /// </summary>
        /// <param name="context">The database context to attach / detach.</param>
        /// <param name="dataStoreEntity">The entity (sub)graph as retrieved from the data store.</param>
        /// <param name="updatingEntity">The entity (sub)graph after it has been updated</param>
        private static void RecursiveGraphUpdate(DbContext context, object dataStoreEntity, object updatingEntity, UpdateMember member)
        {
            // Get item Type
            var itemType = member.Accessor.PropertyType.IsGenericType
                ? member.Accessor.PropertyType.GetGenericArguments().First()
                : member.Accessor.PropertyType;

            // Create Helpful Linq Methods
            Func <IEnumerable, IEnumerable> distinct        = l => (IEnumerable)typeof(Enumerable).GetMethods().Single(m => m.Name.Equals("Distinct") && m.GetParameters().Count() == 1).MakeGenericMethod(new[] { itemType }).Invoke(null, new object[] { l });
            Func <IEnumerable, IEnumerable> toList          = l => (IEnumerable)typeof(Enumerable).GetMethod("ToList").MakeGenericMethod(new[] { itemType }).Invoke(null, new object[] { l });
            Func <IEnumerable, object>      singleOrDefault = l => typeof(Enumerable).GetMethods().Single(m => m.Name.Equals("SingleOrDefault") && m.GetParameters().Count() == 1).MakeGenericMethod(new[] { itemType }).Invoke(null, new object[] { l });

            // Get member's navigation property
            var memberNavProp = (member.Parent == null)
                ? member.IncludeString
                : member.IncludeString.Substring((member.Parent.IncludeString ?? "").Length).TrimStart('.');


            if (member.IsCollection)
            {
                // We are dealing with a collection

                // Get distinctly the new itens
                var updateValues = (IEnumerable)member.Accessor.GetValue(updatingEntity, null);
                updateValues = updateValues != null?toList(distinct(updateValues)) : new List <object>();

                // Get database values
                IEnumerable dbCollection;
                var         actualEntityIsOnTheContext = updatingEntity == dataStoreEntity;
                if (actualEntityIsOnTheContext)
                {
                    dbCollection = member.IsOwned
                        ? toList(context.Entry(updatingEntity).Collection(memberNavProp).Query())
                        : toList(((ObjectQuery)context.Entry(updatingEntity).Collection(memberNavProp).Query()).Execute(MergeOption.OverwriteChanges));

                    // Assure the entity's child collection wasn't refreshed when getting db values.
                    member.Accessor.SetValue(updatingEntity, updateValues, null);
                }
                else
                {
                    dbCollection = (IEnumerable)member.Accessor.GetValue(dataStoreEntity, null);
                }


                Type dbCollectionType = dbCollection.GetType();
                Type innerElementType;

                if (dbCollectionType.IsArray)
                {
                    innerElementType = dbCollectionType.GetElementType();
                }
                else if (dbCollectionType.IsGenericType)
                {
                    innerElementType = dbCollectionType.GetGenericArguments()[0];
                }
                else
                {
                    throw new InvalidOperationException("GraphDiff required the collection to be either IEnumerable<T> or T[]");
                }

                var keyFields = context.GetKeysFor(innerElementType);
                var dbHash    = MapCollectionToDictionary(keyFields, dbCollection);

                // Iterate through the elements from the updated graph and try to match them against the db graph.
                List <object> additions = new List <object>();
                foreach (object updateItem in updateValues)
                {
                    var key = CreateHash(keyFields, updateItem);
                    // try to find in db collection
                    object dbItem;
                    if (dbHash.TryGetValue(key, out dbItem))
                    {
                        // If we own the collection
                        if (member.IsOwned)
                        {
                            context.Entry(dbItem).CurrentValues.SetValues(updateItem); // match means we are updating
                            AttachCyclicNavigationProperty(context, dataStoreEntity, updateItem);

                            foreach (var childMember in member.Members)
                            {
                                RecursiveGraphUpdate(context, dbHash[key], updateItem, childMember);
                            }
                        }

                        dbHash.Remove(key); // remove to leave only db removals in the collection
                    }
                    else
                    {
                        additions.Add(updateItem);
                    }
                }

                // Removal of dbItem's left in the collection
                foreach (var dbItem in dbHash.Values)
                {
                    // Removing dbItem, assure it's children will me deleted.
                    foreach (var subMember in member.Members)
                    {
                        RecursiveGraphUpdate(context, dbItem, dbItem, subMember);
                    }

                    // Own the collection so remove it completely.
                    if (member.IsOwned)
                    {
                        context.Set(ObjectContext.GetObjectType(dbItem.GetType())).Remove(dbItem);
                    }

                    dbCollection.GetType().GetMethod("Remove").Invoke(dbCollection, new[] { dbItem });
                }

                // Add elements marked for addition
                foreach (object newItem in additions)
                {
                    if (!member.IsOwned)
                    {
                        context.Set(ObjectContext.GetObjectType(newItem.GetType())).Attach(newItem);
                        if (GraphDiffConfiguration.ReloadAssociatedEntitiesWhenAttached)
                        {
                            context.Entry(newItem).Reload();
                        }
                    }

                    // Otherwise we will add to object
                    dbCollection.GetType().GetMethod("Add").Invoke(dbCollection, new[] { newItem });
                    AttachCyclicNavigationProperty(context, dataStoreEntity, newItem);
                }
            }
            else // not collection
            {
                var actualEntityIsOnTheContext = updatingEntity == dataStoreEntity;
                var dbvalue = (actualEntityIsOnTheContext && member.IsOwned)
                    ? singleOrDefault(context.Entry(updatingEntity).Reference(memberNavProp).Query())
                    : member.Accessor.GetValue(dataStoreEntity, null);



                var newvalue = member.Accessor.GetValue(updatingEntity, null);
                if (dbvalue == null && newvalue == null) // No value
                {
                    return;
                }

                // If we own the collection then we need to update the entities otherwise simple relationship update
                if (!member.IsOwned)
                {
                    if (dbvalue != null)
                    {
                        context.Entry(dbvalue).Reload();
                        context.Entry(dbvalue).State = EntityState.Unchanged;
                    }


                    if (newvalue == null)
                    {
                        member.Accessor.SetValue(dataStoreEntity, null, null);
                        return;
                    }

                    if (dbvalue != null && newvalue != null)
                    {
                        var keyFields = context.GetKeysFor(ObjectContext.GetObjectType(newvalue.GetType()));
                        var newKey    = CreateHash(keyFields, newvalue);
                        var updateKey = CreateHash(keyFields, dbvalue);
                        if (newKey == updateKey)
                        {
                            return; // do nothing if the same key
                        }
                    }

                    if (context.Entry(newvalue).State == EntityState.Detached)
                    {
                        context.Set(ObjectContext.GetObjectType(newvalue.GetType())).Attach(newvalue);
                    }

                    member.Accessor.SetValue(dataStoreEntity, newvalue, null);
                    context.Entry(newvalue).State = EntityState.Unchanged;
                    if (GraphDiffConfiguration.ReloadAssociatedEntitiesWhenAttached)
                    {
                        context.Entry(newvalue).Reload();
                    }
                }
                else
                {
                    if (dbvalue != null && newvalue != null)
                    {
                        // Check if the same key, if so then update values on the entity
                        var keyFields = context.GetKeysFor(ObjectContext.GetObjectType(newvalue.GetType()));
                        var newKey    = CreateHash(keyFields, newvalue);
                        var updateKey = CreateHash(keyFields, dbvalue);

                        // perform update if the same
                        if (updateKey == newKey)
                        {
                            context.Entry(dbvalue).CurrentValues.SetValues(newvalue);
                        }
                        else
                        {
                            member.Accessor.SetValue(dataStoreEntity, newvalue, null);
                        }
                    }
                    else
                    {
                        member.Accessor.SetValue(dataStoreEntity, newvalue, null);
                    }

                    AttachCyclicNavigationProperty(context, dataStoreEntity, newvalue);

                    // TODO
                    foreach (var childMember in member.Members)
                    {
                        RecursiveGraphUpdate(context, dbvalue, newvalue, childMember);
                    }
                }
            }
        }
 public Result UpdateMember(UpdateMember model)
 {
     return(member.Update(model));
 }
Пример #10
0
        /// <summary>
        /// Updates a detached graph of entities by performing a diff comparison of object keys.
        /// Author: Brent McKendrick
        /// </summary>
        /// <param name="context">The database context to attach / detach.</param>
        /// <param name="dataStoreEntity">The entity (sub)graph as retrieved from the data store.</param>
        /// <param name="updatingEntity">The entity (sub)graph after it has been updated</param>
        private static void RecursiveGraphUpdate(DbContext context, object dataStoreEntity, object updatingEntity, UpdateMember member)
        {
            if (member.IsCollection)
            {
                // We are dealing with a collection
                var updateValues = (IEnumerable)member.Accessor.GetValue(updatingEntity, null);
                var dbCollection = (IEnumerable)member.Accessor.GetValue(dataStoreEntity, null);

                if (updateValues == null)
                {
                    updateValues = new List <object>();
                }

                Type dbCollectionType = dbCollection.GetType();
                Type innerElementType;

                if (dbCollectionType.IsArray)
                {
                    innerElementType = dbCollectionType.GetElementType();
                }
                else if (dbCollectionType.IsGenericType)
                {
                    innerElementType = dbCollectionType.GetGenericArguments()[0];
                }
                else
                {
                    throw new InvalidOperationException("GraphDiff required the collection to be either IEnumerable<T> or T[]");
                }

                var keyFields = context.GetKeysFor(innerElementType);
                var dbHash    = MapCollectionToDictionary(keyFields, dbCollection);

                // Iterate through the elements from the updated graph and try to match them against the db graph.
                List <object> additions = new List <object>();
                foreach (object updateItem in updateValues)
                {
                    var key = CreateHash(keyFields, updateItem);
                    // try to find in db collection
                    object dbItem;
                    if (dbHash.TryGetValue(key, out dbItem))
                    {
                        // If we own the collection
                        if (member.IsOwned)
                        {
                            context.Entry(dbItem).CurrentValues.SetValues(updateItem); // match means we are updating
                            AttachCyclicNavigationProperty(context, dataStoreEntity, updateItem);

                            foreach (var childMember in member.Members)
                            {
                                RecursiveGraphUpdate(context, dbHash[key], updateItem, childMember);
                            }
                        }

                        dbHash.Remove(key); // remove to leave only db removals in the collection
                    }
                    else
                    {
                        additions.Add(updateItem);
                    }
                }

                // Removal of dbItem's left in the collection
                foreach (var dbItem in dbHash.Values)
                {
                    // Own the collection so remove it completely.
                    if (member.IsOwned)
                    {
                        context.Set(ObjectContext.GetObjectType(dbItem.GetType())).Remove(dbItem);
                    }

                    dbCollection.GetType().GetMethod("Remove").Invoke(dbCollection, new[] { dbItem });
                }

                // Add elements marked for addition
                foreach (object newItem in additions)
                {
                    if (!member.IsOwned)
                    {
                        context.Set(ObjectContext.GetObjectType(newItem.GetType())).Attach(newItem);
                        if (GraphDiffConfiguration.ReloadAssociatedEntitiesWhenAttached)
                        {
                            context.Entry(newItem).Reload();
                        }
                    }

                    // Otherwise we will add to object
                    dbCollection.GetType().GetMethod("Add").Invoke(dbCollection, new[] { newItem });
                    AttachCyclicNavigationProperty(context, dataStoreEntity, newItem);
                }
            }
            else // not collection
            {
                var dbvalue  = member.Accessor.GetValue(dataStoreEntity, null);
                var newvalue = member.Accessor.GetValue(updatingEntity, null);
                if (dbvalue == null && newvalue == null) // No value
                {
                    return;
                }

                // If we own the collection then we need to update the entities otherwise simple relationship update
                if (!member.IsOwned)
                {
                    if (newvalue == null)
                    {
                        member.Accessor.SetValue(dataStoreEntity, null, null);
                        return;
                    }

                    if (dbvalue != null && newvalue != null)
                    {
                        var keyFields = context.GetKeysFor(ObjectContext.GetObjectType(newvalue.GetType()));
                        var newKey    = CreateHash(keyFields, newvalue);
                        var updateKey = CreateHash(keyFields, dbvalue);
                        if (newKey == updateKey)
                        {
                            return; // do nothing if the same key
                        }
                    }

                    if (context.Entry(newvalue).State == EntityState.Detached)
                    {
                        context.Set(ObjectContext.GetObjectType(newvalue.GetType())).Attach(newvalue);
                    }

                    member.Accessor.SetValue(dataStoreEntity, newvalue, null);
                    context.Entry(newvalue).State = EntityState.Unchanged;
                    if (GraphDiffConfiguration.ReloadAssociatedEntitiesWhenAttached)
                    {
                        context.Entry(newvalue).Reload();
                    }
                }
                else
                {
                    if (dbvalue != null && newvalue != null)
                    {
                        // Check if the same key, if so then update values on the entity
                        var keyFields = context.GetKeysFor(ObjectContext.GetObjectType(newvalue.GetType()));
                        var newKey    = CreateHash(keyFields, newvalue);
                        var updateKey = CreateHash(keyFields, dbvalue);

                        // perform update if the same
                        if (updateKey == newKey)
                        {
                            context.Entry(dbvalue).CurrentValues.SetValues(newvalue);
                        }
                        else
                        {
                            member.Accessor.SetValue(dataStoreEntity, newvalue, null);
                        }
                    }
                    else
                    {
                        member.Accessor.SetValue(dataStoreEntity, newvalue, null);
                    }

                    AttachCyclicNavigationProperty(context, dataStoreEntity, newvalue);

                    // TODO
                    foreach (var childMember in member.Members)
                    {
                        RecursiveGraphUpdate(context, dbvalue, newvalue, childMember);
                    }
                }
            }
        }