示例#1
0
 public void UpdateMember(int id, UpdateMamberModel model)
 {
     try
     {
         var memberUpdate = this.MemberItem.SingleOrDefault(m => m.id == id);
         if (memberUpdate == null)
         {
             throw new Exception("Note found member");
         }
         this.db.Members.Attach(memberUpdate);
         memberUpdate.email     = model.email;
         memberUpdate.firstname = model.firstname;
         memberUpdate.lastname  = model.lastname;
         memberUpdate.position  = model.position;
         memberUpdate.updated   = DateTime.Now;
         memberUpdate.role      = model.role;
         if (!string.IsNullOrEmpty(model.password))
         {
             memberUpdate.password = PasswordHashModel.Hash(model.password);
         }
         this.onConverBase64ToImage(memberUpdate, model.image);
         this.db.Entry(memberUpdate).State = System.Data.Entity.EntityState.Modified;
         this.db.SaveChanges();
     }catch (Exception e)
     {
         throw e.GetBaseException();
     }
 }
示例#2
0
 public IHttpActionResult PutUpdateMember(int id, [FromBody] UpdateMamberModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             this.memberService.UpdateMember(id, model);
             return(Ok("Update successful"));
         }catch (Exception e)
         {
             ModelState.AddModelError("Exception", e.Message);
         }
     }
     return(BadRequest(ModelState.GetErrorModelState()));
 }