public bool updateById(int id, AdminsModel updateAdmin) { try { var currentAdmin = this.getAdminById(id); if (currentAdmin != null) { currentAdmin.full_name = updateAdmin.full_name; currentAdmin.email = updateAdmin.email; //currentAdmin.password = updateAdmin.password; currentAdmin.gender = updateAdmin.gender; currentAdmin.date_of_birth = updateAdmin.date_of_birth; currentAdmin.phone_number = updateAdmin.phone_number; currentAdmin.address = updateAdmin.address; currentAdmin.role = int.Parse(updateAdmin.role.ToString()); db.Entry(currentAdmin).State = EntityState.Modified; db.SaveChanges(); return(true); } return(false); }catch (Exception e) { throw e; } }
public bool create(AdminsModel newAdmin) { try { admin admin = new admin(); admin.full_name = newAdmin.full_name; admin.email = newAdmin.email; admin.password = new Utils().GetMd5Hash(newAdmin.password); admin.gender = newAdmin.gender; admin.date_of_birth = newAdmin.date_of_birth; admin.phone_number = newAdmin.phone_number; admin.address = newAdmin.address; admin.role = int.Parse(newAdmin.role.ToString()); admin.start_time = DateTime.Now; admin.status = true; db.admins.Add(admin); db.SaveChanges(); return(true); } catch (Exception e) { return(false); } }